I want to stream the contents of a queue so I can use Flow to process the data. Data is added to the queue asynchronously at undefined times.
The Stream.resource looks kind of like this:
Stream.resource(fn -> nil end, fn (_) ->
case Queue.out() do
{:value, value} -> {[value], nil}
:empty -> {[], nil}
end
end, fn (_) -> nil end)
So my question is: Is it wise or even possible to block in Stream.resource when the queue is empty? Because in the shown code above it would basically be polling for the next element in the queue.
I thought of creating some kind of check for a non empty queue which sleeps for a while when it’s empty before checking again.