跳转到内容

Rebol 编程/dispatch

来自维基教科书,开放书籍,开放世界
DISPATCH port-block 

等待端口块。当事件发生时,调度端口处理程序块。

DISPATCH 是一个函数值。

  • port-block -- 端口处理程序对的块(端口也可以是超时)。(类型:块)

源代码

[编辑 | 编辑源代码]
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]
    ]
]
华夏公益教科书