Drain internal channels
Gracefully finish producer/consumer Flows without losing in-flight channel messages.
Problem and approach
This example Flow demonstrates a Flow where one thread (A) is responsible for sending commands through the internal channel, while another thread (B) continuously loops, waiting to receive those messages. It's important for thread B to receive a signal indicating when it should finish its task, as we want to avoid abruptly shutting it down and potentially losing messages. In this scenario, thread A communicates with thread B through an internal channel, sending a command to indicate that the final message has been received, allowing thread B to gracefully complete its process without losing any messages.
Code examples
Full runnable samples live under examples/{go,java,python,typescript} (HTTP prefix /design-pattern/... where applicable).
# See examples/python/dex_examples/patterns/workflow/drainchannels/internal/