[plt-scheme] Asynchronous Let

From: Erich Rast (erich at snafu.de)
Date: Thu Jul 5 06:52:06 EDT 2007


I'm looking for something like this as a macro:

(let/async ((result (lambda () (do-something))))
   (when (exn? result)
     (error "oops"))
   (display result))

This would start a thread running (lambda () (do-something)) and  
immediately return. When the task finishes or an exception occurs in  
it, the result of the thunk (or the exception) is bound to the  
variable result and the body is evaluated concurrently. If more than  
one variable/thunk pairs are given, the body should be executed only  
after evaluation of all of them has finished.

I'm not particularly good at writing macros and not familiar with  
mzscheme's syntax extensions for better debugging support. So I ask  
here just in case someone has already implemented such a macro. (This  
is not a homework assignment.)

I'd like to use this idiom for writing asynchronous operations,  
particularly with socket connections, in an easy to read style. Or is  
there a better way to do this?

Best regards,


Posted on the users mailing list.