Rebol Programming/dispatch

USAGE:

edit
DISPATCH port-block 

DESCRIPTION:

edit

Wait for a block of ports. As events happen, dispatch port handler blocks.

DISPATCH is a function value.

ARGUMENTS

edit
  • port-block -- Block of port handler pairs (port can be timeout too). (Type: block)

SOURCE CODE

edit
dispatch: func [
    {Wait for a block of ports. As events happen, dispatch port handler blocks.} 
    port-block [block!] {Block of port handler pairs (port can be timeout too).} 
    /local ports awake timeblk result
][
    ports: copy [] 
    foreach [port job] port-block: reduce port-block [
        if any [number? port time? port] [if none? timeblk [timeblk: :job]] 
        append ports port
    ] 
    forever [
        either awake: wait/all ports [
            if foreach item awake [
                set/any 'result do select port-block item item 
                if all [value? 'result 'break = :result] [break/return true]
            ] [break]
        ] [do :timeblk]
    ]
]