<div dir="ltr">Note that this is what orElse is for, turning a blocking API unto a choice. You could write tryWriteTBQueue as:<div><br></div><div> tryWriteTBQueue queue v = (writeTBQueue queue v >> return True) `orElse` (return False)</div><div><br></div><div>Ryan</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Feb 28, 2015 at 11:56 AM, Alex Hammel <span dir="ltr"><<a href="mailto:ahammel87@gmail.com" target="_blank">ahammel87@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Perfect, thanks!</p><div class="HOEnZb"><div class="h5">
<div class="gmail_quote">On 28 Feb 2015 08:51, "Yuras Shumovich" <<a href="mailto:shumovichy@gmail.com" target="_blank">shumovichy@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sat, 2015-02-28 at 08:31 -0800, Alex Hammel wrote:<br>
> Forwarding from Haskell-Beginners:<br>
><br>
> Hi list,<br>
><br>
> It would be handy for me to have a bounded STM Queue along the lines of<br>
> TBQueue with the difference that when the queue is full, a call to<br>
> writeTBQueue is a non-blocking no-op.<br>
><br>
> This is in the context of an asynchronous logging system. If the load<br>
> (somehow) gets heavy enough that the log message queue is taking up a lot<br>
> of memory, It's better to lose a few log messages than to have processes<br>
> block until the logger catches up.<br>
><br>
> Are there any off-the-shelf solutions?<br>
<br>
You can try the stm-chans package:<br>
<a href="http://hackage.haskell.org/package/stm-chans-3.0.0.2/docs/Control-Concurrent-STM-TBMQueue.html#v:tryWriteTBMQueue" target="_blank">http://hackage.haskell.org/package/stm-chans-3.0.0.2/docs/Control-Concurrent-STM-TBMQueue.html#v:tryWriteTBMQueue</a><br>
<br>
Thanks,<br>
Yuras<br>
<br>
><br>
> Cheers,<br>
> Alex<br>
> _______________________________________________<br>
> Haskell-Cafe mailing list<br>
> <a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br>
<br>
</blockquote></div>
</div></div><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>