Closed danjohansson closed 9 years ago
on-drained
is called once the stream has been drained of messages, which is not necessarily the same as when all of its messages have been fully processed downstream (how would the stream know when you're done with its contents?). Checking whether it's drained in the consume
callback won't always work, since it might be still open when it receives its last message, and only be closed subsequently, which won't pass anything to the callback.
Short answer is: use (byte-streams/transfer s (io/file ...))
. Longer answer is that you need to use a loop to consume the messages one by one, and only do the resource closing once you read from the source, get the "drained" value, and then clean up.
Thanks for clearing things up! Also thanks for adding the new documention on custom execution models.
I have some problem detecting when to close the output stream in the example below. I do not know if it is ok to close the file in the on-drained callback. I noticed different behaviour when using stream and source as described in the code below.
Whats the recommended pattern for writing a stream down to a file as attempted here?