Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

wait-for-result swallows next message on timeout #63

Closed
databu opened this issue Apr 4, 2013 · 3 comments
Closed

wait-for-result swallows next message on timeout #63

databu opened this issue Apr 4, 2013 · 3 comments

Comments

@databu
Copy link
Contributor

databu commented Apr 4, 2013

When wait-for-result is called using a call to (read-channel ch) and with a timeout, and does indeed timeout, the next message enqueued in ch seems still to be consumed by it. For example, this code results in a TimeoutException instead of the expected result :m

(let [ch (channel)]
     (try
       (wait-for-result (read-channel ch) 0)
       (catch java.util.concurrent.TimeoutException _ nil))
     (enqueue ch :m)
     (wait-for-result (read-channel ch) 0)) 

In contrast, calling read-channel* instead with a timeout works as expected:

(let [ch (channel)]
     (try
       (wait-for-result (read-channel* ch :timeout 0))
       (catch java.util.concurrent.TimeoutException _ nil))
     (enqueue ch :m)
     (wait-for-result (read-channel* ch :timeout 0)))
@ztellman
Copy link
Owner

ztellman commented Apr 5, 2013

This is an easy enough change, but it's not clear to me that specifying a timeout for wait-for-result suggests that the timeout should apply to anything other than the "wait". As you point out, adding a timeout to read-channel causes the read itself to timeout.

Could you expand on why you think this is not "expected" behavior?

@amalloy
Copy link
Collaborator

amalloy commented Apr 19, 2013

FWIW I think it makes more sense for read-channel to still consume the item. Your scenario is like "Read the next item. If it finishes within the next 0 ms, let me know." The read is still pending.

@databu
Copy link
Contributor Author

databu commented Apr 20, 2013

I think you're right about this, I was confused as to how result channels are supposed to work (some doc would be great :) ). What I really want is wait-for-message.

@databu databu closed this as completed Apr 20, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants