Jump to content

Rebol Programming/dispatch

From Wikibooks, open books for an open world

USAGE:

[edit | edit source]
DISPATCH port-block 

DESCRIPTION:

[edit | edit source]

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

DISPATCH is a function value.

ARGUMENTS

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

SOURCE CODE

[edit | edit source]
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]
    ]
]