Container
Homogeneous resource (continuous or discrete amounts).
Container
A resource holding up to capacity units of homogeneous content.
Works for both continuous amounts (float) and discrete counts (int). Blocking operations return an Event whose value is the amount transferred. Non-blocking operations raise on failure.
Cancelled get events restore the level via _on_cancel so that FirstOf does not silently discard consumed content.
capacity
property
Maximum capacity.
level
property
Current content level.
get(amount)
Return an Event that resolves to amount when content is available.
If sufficient content is available immediately, the Event is pre-triggered and _on_cancel is set to restore the level if FirstOf later discards the result.
put(amount)
Return an Event that resolves to amount when space is available.
try_get(amount)
Remove and return amount of content, or raise ContainerEmpty.
try_put(amount)
Add amount of content, or raise ContainerFull.
ContainerEmpty
Bases: Exception
Raised by Container.try_get() when there is insufficient content.
ContainerFull
Bases: Exception
Raised by Container.try_put() when there is insufficient space.