Queue.bounded for producer-consumer
Queue decouples producers from consumers with back-pressure. Use Queue.bounded(n) for a queue with capacity. Queue.offer adds items; Queue.take removes them. If the queue is full, offer suspends; if empty, take suspends.
- Use
Queue.bounded<A>(capacity)to create a queue - Use
Queue.offer(queue, value)to add items - Use
Queue.take(queue)to remove and return the oldest item
Loading code editor...