<div dir="ltr"><div><div><div>I discussed this with Vincent and Asumu today in person. Here are some of the results of our conversation:<br><br></div>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.<br>
<br></div>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.<br>
<br></div>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?<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Aug 11, 2013 at 2:12 PM, Jonathan Schuster <span dir="ltr"><<a href="mailto:schuster@ccs.neu.edu" target="_blank">schuster@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>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?<span class="HOEnZb"><font color="#888888"><br>
<br></font></span></div><span class="HOEnZb"><font color="#888888">Jonathan<br></font></span></div>
</blockquote></div><br></div>