In Rosencrantz I am trying to implement support for streaming responses with transfer econding chunked.
These can be used to stream large files, or to represent the case where the data for the response comes piecewise.
The handler to produce these responses should get as input some kind of stream. What datatype should I use to represent the stream? If all data was available at once, I could use an iterator. But I see that the support for async operations is also implemented on top of iterators, which are used to simulate coroutines.
I have the feeling that an iterator can somehow be used to represent an asynchronous stream - by making some smart ping pong between it and the procedure that consumes it - but I cannot quite put it down clearly.
Any ideas?
There is a new asyncstreams module in nimboost. It provides API close to streams module in stdlib, so it's probably too low-level for your standards, though.
As for a cleaner abstraction, you might want to look into iteratees for that - seems close to what you're talking about.