[REBOL] Async Callback
From: charles::wardell::dendrite::com at: 18-Nov-2004 10:58
I finally managed to get the client and server working with Anton's
I don't fully understand the callback mechanism. Here is the code for
the test server below. Let's say I wanted to print the #'s 1 through a
million but handle the events as they occur. Where would I put my print
statement? Am I wrong in assuming that this is the way the event works.
I would like to put some standard processing in the event loop but have
no idea where to put it.
listen: open/no-wait tcp://:8181
listen/awake: func [l /local p] [
;print "Server: A Client connected"
p: first listen
port: make port! [scheme: 'async sub-port: p]
port/awake: do server-handler
server-handler: [use [ buffers ] [
buffers: copy 
func [port [port!] state [word! error!] /local tmp cmd buffer] [
if error? :state [print mold disarm state return true]
switch state [
;print "Server: connect"
;print "Server: read"
if not find buffers port [append buffers reduce [port
print ["buffers length:" length? buffers]
append buffer copy port
while [tmp: find buffer newline]
cmd: copy/part buffer tmp
remove/part buffer next tmp
;print ["Server: Recieved:" mold cmd]
print [mold cmd]
false ;close port
;print "Server: write"
;print "Server: close"
insert tail system/ports/wait-list listen