Bounded variant of AsyncPipe which buffers a fixed number of writes before blocking new attempts to write until the buffer is drained.
Synopsis
Declared in <folly/coro/AsyncPipe.h>
template<
typename T,
bool SingleProducer = true,
template<
typename,
bool,
bool> typename QueueType = SmallUnboundedQueue>
class BoundedAsyncPipe;
Description
Usage: auto [generator, pipe]= BoundedAsyncPipe<T>::create(/* tokens */ 10); co_await pipe.write(std::move(entry)); auto entry = co_await generator.next().value();
write() is a coroutine which only blocks when no capacity is remaining. write() returns false if the read‐end has been destroyed or was destroyed while blocking, only throwing OperationCanceled if the parent coroutine was canceled while blocking.
try_write() is offered which will never block, but will return false and not write if no capacity is remaining or the read end is already destroyed.
close() functions the same as AsyncPipe, and must be invoked before destruction if an onClose callback is attached.
Type Aliases
Name |
Description |
The underlying unbounded pipe type wrapped by this bounded pipe. |
Member Functions
Name |
Description |
|
|
Returns the remaining buffer capacity available for writes. |
|
Returns the number of buffered writes currently occupying the pipe. |
|
Returns whether the pipe has been closed. |
|
Writes a value without blocking, failing if no capacity remains. |
|
Writes a value, suspending while the buffer is full. |