[racket] Peekable asynchronous channel?

From: Jonathan Schuster (schuster at ccs.neu.edu)
Date: Mon Aug 12 15:58:44 EDT 2013

I discussed this with Vincent and Asumu today in person. Here are some of
the results of our conversation:

What I really want is a function like "async-channel-non-empty-event" that
returns an event that's ready for synchronization when async-channel-get
would not block (but the event does not consume a message). The predicate
async-channel-empty? could also be useful for similar reasons.

The naive implementation of a peek event doesn't work because of the
following use case: On some thread (call it thread 1), the thread syncs on
a peek event and gets the peeked value. Thread 1 decides it likes the value
and attempts to pull it from the channel. However, at the same time another
thread (thread 2) pulls out that value, so thread 1 ends up with a
different value, which it doesn't know how to process. That use case needs
a more complicated API that handles more of the thread synchronization. My
own work doesn't involve this use case, though.

For now, I'm going to write something to act like a channel with a
non-empty event, but do people think async-channel-non-empty and
async-channel-get would be useful to have in Racket proper? If not, would
there be interest in providing that functionality as a package?


On Sun, Aug 11, 2013 at 2:12 PM, Jonathan Schuster <schuster at ccs.neu.edu>wrote:

> I'd like to have an asynchronous channel that does not remove a value from
> its buffer on sync, so that I can separate the code that waits for a
> message from the code that removes everything currently in the channel. In
> some sense, I want sync to do a "peek", not a "get". Does anything like
> this exist in Racket (or perhaps in the package system), or would I have to
> write it myself?
>
> Jonathan
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130812/7f8bc979/attachment.html>

Posted on the users mailing list.