Operator "consume" internals #213
vitaly-t
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Just to show what operator consume really does underneath - compare the following custom operator examples...
If we were to take the code example from operator consume, and make it a custom operator, it would be like this:
To do the same, but without consume, and using concurrencyFork instead:
And without using any helpers, just direct implementation:
All of the above would produce the same result, though the latter would not be able to handle errors thrown during pipeline construction, and it is what should be generally considered an unsafe approach.
To understand why operator consume represents a good pattern, consider an example from this discussion:
Operator consume makes it easy and safe to link up external objects like that, inside custom operators, and manage their lifecycle. And when used directly, it is the only way to consume the entire source when it is an iterator (not iterable).
Beta Was this translation helpful? Give feedback.
All reactions