Closed jarppe closed 6 years ago
It's possible that the code is not robust to interrupt
being called on the thread. I'll take a look.
Sorry for the delay, but I've looked at your example more closely and this seems to be working as expected. By calling take!
, you've claimed the head of the stream, even if you fail to do anything with the deferred. To actually cancel the consumption of the first element in the stream, you have to fill the deferred with another value before a message comes through.
If I have a thread that is waiting for value from dereffred and that thread is interrupted, the next value to the stream is lost.
I try to give a minimal example that shows this:
This prints:
The first future gets the referred from
s/take!
and is waiting a value from it, but that future is cancelled.Next I send values
0
,1
, and2
to the stream. The future taking and printing values from that streams receives1
and2
.Is this expected or perhaps I have misunderstood something.
I got this problem when I created a set of workers using an Executor, and in cleanup I just called
(.shutdownNow executor)
that causes all worker threads to be interrupted. After that I recreated some worker threads and noticed that the first items sent to stream were not processed by those workers.