Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Dispatch

From: ptretter::charter::net at: 18-Oct-2000 10:26

Allen, I looked at Dispatch but have some questions regarding it. Is this a replacement for wait or used in conjunction with wait. If used also with wait then I have a question on the wait command. Take for example the following from the docs concerning wait on multiple ports: The wait function will return the port that is ready or none if the timeout occurred. ready: wait [port1 port2 10] if ready [data: copy ready] The above example will read data from the first ready port if a timeout did not occur. In this case how would you get data for a RESPECTIVE port. I may want to distinguish between data coming from port1 apart from port2. In the case above the word "ready" will contain data from either port and I want be able to determine which port the data came from. The help for dispatch is:
>> help dispatch
USAGE: DISPATCH port-block DESCRIPTION: Wait for a block of ports. As events happen, dispatch p ort handler blocks. DISPATCH is a function value. ARGUMENTS: port-block -- Block of port handler pairs (port can be timeout too). (Type: block) It would appear by the description for dispatch that it replaces the wait command. Also the souce for dispatch includes the wait command which further makes me suspect that is the case - 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] ] ] The only data on dispatch from the new /core docs is: You can also use the dispatch function to evaluate a block or function based on the results of a wait on multiple ports. dispatch [ port1 [print "port1 awake"] port2 [print "port2 awake"] 10 [print "timeout!"] ] Obviously this leaves me scratching my head waiting for the "?" to appear above my head. Any clarification you can provide. I have successfully implemented client and server but now wish to use one script to open different ports and monitor for different data on those ports. Paul Tretter