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.

ARGUMENTSEdit

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

SOURCE CODEEdit

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]
    ]
]
Last modified on 27 October 2012, at 22:13