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

Pipe

The underlying unbounded pipe type wrapped by this bounded pipe.

Member Functions

Name

Description

close

close overloads

getAvailableSpace

Returns the remaining buffer capacity available for writes.

getOccupiedSpace

Returns the number of buffered writes currently occupying the pipe.

isClosed

Returns whether the pipe has been closed.

try_write

Writes a value without blocking, failing if no capacity remains.

write

Writes a value, suspending while the buffer is full.

Static Member Functions

Name

Description

create

Creates a bounded pipe, returning its read generator and write end.

Created with MrDocs