jschell wrote:
Never understood that need. That can only apply if getting the item requires acquiring other resources and in that case, especially given 5, then either make the caller responsible for that or wrap it is a proxy and that does it.
I have a worker thread that monitors the queue. There is not always something in the queue. In fact, most of the time, it will be empty or close to it. Clearly, I should not spin the CPU when the queue is empty. As for being able to cancel the blocking operation, well... if you wait on a syncronization object indefinitely (the blocking part), it keeps the thread alive (which will keep the process alive) [EDIT: unless the thread is a background thread]. Not a desirable behavior when you, say, want to be able to shut down your app :). Using a timeout is also not a solution, as if you set your timeout too low, you'll spin the CPU, and if you set it too high, you'll have that annoying behavior of your app taking a long time to shut down.
jschell wrote:
Its a generic class/API which means if there is a failure mode then it must throw exceptions.
I wouldn't consider cancelling a blocking operation to be a failure if the cancellation was intended. But some would...
jschell wrote:
Not that hard and I suspect there are a vast number of examples on the internet.
You'd be surprised ;).