-
Notifications
You must be signed in to change notification settings - Fork 24
Channels and Flows ‐ When to use each of them
Devrath edited this page Dec 23, 2023
·
4 revisions
- Channels and Flows are both used for concurrency in kotlin co-routines.
- They both help to achieve
asynchronous behavior.
Channels provide a low-level API compared to flows, If you need more fine-grained control over co-routines and emissions of data, the channels are a better fit.
Channels can either be buffered or can not be buffered, This allows us to control the amount of data that is being sent even before receiving data in the receiver.
Channels help in implementing complex communication patterns, Ex: Making the channel wait before multiple channels perform complex operations using the SELECT operation.
Channels have explicit support for the channel close operation(isClosedForReceive, isClosedForSend), allowing coroutines to react to the end of the communication.
