class Strategy[A]
How a PubSub handles messages that do not fit and wakes parked
takes (Effect's PubSub.Strategy). BackPressureStrategy,
DroppingStrategy and SlidingStrategy implement it; so can user
code. Subclassing it inherits the two complete_* hooks as the
built-ins have them.
Attributes#
| Attribute | Type | Description |
|---|---|---|
shutdown | Effect[None] | Run after the hub shut down and unsubscribed everyone. |
Functions#
handle_surplus#
handle_surplus(pubsub, subscribers, elements, is_shutdown, ended) -> Effect[bool]A publish's elements did not fit. The publisher may have
yielded since publish checked ended(), so check it again
before parking or publishing the surplus.
| Parameter | Type | Description |
|---|---|---|
pubsub | Atomic[A] | |
subscribers | Subscribers[A] | |
elements | Iterable[A] | |
is_shutdown | Callable[[], bool] | |
ended | Callable[[], Option[A]] |
Returns Effect[bool]
def handle_surplus(
self,
pubsub: Atomic[A],
subscribers: Subscribers[A],
elements: Iterable[A],
is_shutdown: Callable[[], bool],
ended: Callable[[], Option[A]],
) -> Effect[bool]:
"""A publish's ``elements`` did not fit. The publisher may have
yielded since ``publish`` checked ``ended()``, so check it again
before parking or publishing the surplus."""
...on_pubsub_empty_space_unsafe#
on_pubsub_empty_space_unsafe(pubsub, subscribers) -> NoneA subscriber read, so the store may have room.
| Parameter | Type | Description |
|---|---|---|
pubsub | Atomic[A] | |
subscribers | Subscribers[A] |
def on_pubsub_empty_space_unsafe(self, pubsub: Atomic[A], subscribers: Subscribers[A]) -> None:
"""A subscriber read, so the store may have room."""
...complete_pollers_unsafe#
complete_pollers_unsafe(pubsub, subscribers, subscription, pollers) -> NoneGive subscription's messages to its parked takes.
| Parameter | Type | Description |
|---|---|---|
pubsub | Atomic[A] | |
subscribers | Subscribers[A] | |
subscription | BackingSubscription[A] | |
pollers | Pollers[A] |
def complete_pollers_unsafe(
self,
pubsub: Atomic[A],
subscribers: Subscribers[A],
subscription: BackingSubscription[A],
pollers: Pollers[A],
) -> None:
"""Give ``subscription``'s messages to its parked takes."""
while not subscription.is_empty():
poller = pollers.take()
if poller is None:
subscribers.pop(subscription, None)
return
polled = subscription.poll()
if polled is None:
pollers.prepend(poller)
else:
poller.succeed(polled.value)
self.on_pubsub_empty_space_unsafe(pubsub, subscribers)complete_subscribers_unsafe#
complete_subscribers_unsafe(pubsub, subscribers) -> NoneNew messages were stored: give them to the parked takes.
| Parameter | Type | Description |
|---|---|---|
pubsub | Atomic[A] | |
subscribers | Subscribers[A] |
def complete_subscribers_unsafe(self, pubsub: Atomic[A], subscribers: Subscribers[A]) -> None:
"""New messages were stored: give them to the parked takes."""
for subscription in subscribers:
pollers = subscribers.get(subscription)
if pollers is not None:
self.complete_pollers_unsafe(pubsub, subscribers, subscription, pollers)