[plt-scheme] Asynchronous Let

From: Chongkai Zhu (czhu at cs.utah.edu)
Date: Thu Jul 5 10:25:46 EDT 2007

This `let/async' you want is not hard: using syntax-rules only is enough.

(define-syntax let/async
  (syntax-rules ()
    ((_ ((name thunk) ...)
        body ...)
     (thread
      (lambda ()
        (letrec ((name name) ...)
          (for-each thread-wait
               (list
                (thread
                 (lambda ()
                   (set! name
                         (with-handlers (((lambda (x) #t) values))
                           (thunk))))) ...))
          body ...))))))

> 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?


The way exception is bound to "name"s doesn't seems natural to me.

Chongkai


Posted on the users mailing list.