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

[REBOL] Re: /core async example

From: rotenca:telvia:it at: 4-Mar-2004 21:01

Hi, Will I should write it in the following mode. Some notes: 1) you can set the awake function using make port! port: make port! [scheme: 'async host: hst port-id: 80 awake: :handl] you cannot use the words 'host or 'handler because the block is bound to the port before execution (like in an object!: a port is an object!) 2) you can insert a string BEFORE connection is done: you must not wait the 'connect event open port insert port rejoin [{GET / HTTP/1.0} crlf {Host: } port/host crlf crlf] 3) you should not clear the system/ports/wait-list, it can contain some others ports (like event port in View). Here i read the length? before the start and wait until it is returned the same, but it is not the best solution: --------- rebol [] do http://www.rebol.it/giesse/async-protocol.r get-fast: func [hosts /local port len][ len: length? system/ports/wait-list foreach hst hosts [ port: make port! [scheme: 'async host: hst port-id: 80 awake: :handl] open port insert port rejoin [{GET / HTTP/1.0} crlf {Host: } port/host crlf crlf] ] until [wait .1 len = length? system/ports/wait-list] ] handl: func [port [port!] state [word! error!]] [ if error? :state [print mold disarm state return true] switch state [ connect [false] read [false] write [false] close [ data: copy port close port print [port/host length? data] true ] ] ] ;example urls: [ www.rebol.com www.rebol.net www.rebol.org www.apple.com www.oracle.com www.microsoft.com ] loop 5 [get-fast urls] halt --- Ciao Romano