You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given a java.util.Stream, it can be converted to a coroutine Flow in a way that ensures the stream is closed after the flow is finished (consumed or cancelled) like follows:
It could be nice addition to the jdk8 module.
But we cannot name it asFlow for the same reasons we don't have ReceiveChannel.asFlow (we have consumeAsFlow instead): resulting Flow can be used only once
josephlbarnett
changed the title
java.util.Stream.asFlow() operator
java.util.Stream.consumeAsFlow() operator
Oct 8, 2019
* Even though java.lang.Stream is collected rather than consumed, collectAsFlow will clash with Flow terminology where collect is a terminal operator
* Close the stream in the end of collection despite the fact that regular terminal operations don't do that. We are already in suspending world (empty close() call won't make any difference in a common case) and "consume" implies closing the underlying resource (note that we already do it for channels)
* Remove obsolete examples from the module
Fixes#1601
* Even though java.lang.Stream is collected rather than consumed, collectAsFlow will clash with Flow terminology where collect is a terminal operator
* Close the stream in the end of collection despite the fact that regular terminal operations don't do that. We are already in suspending world (empty close() call won't make any difference in a common case) and "consume" implies closing the underlying resource (note that we already do it for channels)
* Remove obsolete examples from the module
Fixes#1601
Given a
java.util.Stream
, it can be converted to a coroutineFlow
in a way that ensures the stream is closed after the flow is finished (consumed or cancelled) like follows:or, alternatively:
Would be slightly more convenient to have a
Stream.consumeAsFlow()
implementation in the coroutines libraries that does so even less verbosely.The text was updated successfully, but these errors were encountered: