[racket] Places and non-blocking get

From: John Clements (clements at brinckerhoff.org)
Date: Sun Jun 1 21:03:12 EDT 2014

On Jun 1, 2014, at 1:18 PM, Charles Hixson <charleshixsn at earthlink.net> wrote:

> I'm contemplating implementing a program in Racket, but it involves
> different processes sending messages to each other, so I need to be able
> to check for the presence of a message without brining everything to a
> halt.  In Python I'd do this using a Queue.  Is there something similar
> in Racket?  The documentation just says that get is a blocking call, but
> if there's a way to check for the presence of a message it doesn't seem
> to mention it.

Sure… it depends on whether you want the ‘put’ to block. If so, then you can use sync/timeout on the channel to see if there’s a message available.

You might also be looking for an actual queue, so that neither side blocks. In this case, you can probably set up a loop on the receiving side that just dumps the events into an asynchronous queue; this shouldn’t be more than three lines of code.

John

John Clements



Posted on the users mailing list.