Publishers

In broqer a subscriber can subscribe to a publisher. After subscription the subscriber is notified about emitted values from the publisher ( starting with the current state). In other frameworks publisher/subscriber are referenced as observable/observer.

broqer.NONE is used as default initialisation. .get() will always return the internal state (even when it’s broqer.NONE). .subscribe() will emit the actual state to the new subscriber only if it is something else than broqer.NONE .

To receive information use following methods to interact with Publisher:

  • .subscribe(subscriber) to subscribe for events on this publisher
  • .unsubscribe(subscriber) to unsubscribe
  • .get() to get the current state

When implementing a Publisher use the following methods:

  • .notify(value) calls .emit(value) on all subscribers
param init:the initial state.
ivar _state:state of the publisher
ivar _inherited_type:
 type class for method lookup
ivar _subscriptions:
 holding a list of subscribers
ivar _on_subscription_cb:
 callback with boolean as argument, telling if at least one subscription exists
ivar _dependencies:
 list with publishers this publisher is (directly or indirectly) dependent on.

Publisher

class broqer.Publisher(init=<class 'broqer.types.NONE'>, type_=None)[source]

In broqer a subscriber can subscribe to a publisher. After subscription the subscriber is notified about emitted values from the publisher ( starting with the current state). In other frameworks publisher/subscriber are referenced as observable/observer.

broqer.NONE is used as default initialisation. .get() will always return the internal state (even when it’s broqer.NONE). .subscribe() will emit the actual state to the new subscriber only if it is something else than broqer.NONE .

To receive information use following methods to interact with Publisher:

  • .subscribe(subscriber) to subscribe for events on this publisher
  • .unsubscribe(subscriber) to unsubscribe
  • .get() to get the current state

When implementing a Publisher use the following methods:

  • .notify(value) calls .emit(value) on all subscribers
Parameters:

init – the initial state.

Variables:
  • _state – state of the publisher
  • _inherited_type – type class for method lookup
  • _subscriptions – holding a list of subscribers
  • _on_subscription_cb – callback with boolean as argument, telling if at least one subscription exists
  • _dependencies – list with publishers this publisher is (directly or indirectly) dependent on.
get() → TValue[source]

Return the state of the publisher.

notify(value: TValue) → None[source]

Calling .emit(value) on all subscribers and store state.

Parameters:value – value to be emitted to subscribers
subscribe(subscriber: Subscriber, prepend: bool = False) → SubscriptionDisposable[source]

Subscribing the given subscriber.

Parameters:
  • subscriber – subscriber to add
  • prepend – For internal use - usually the subscribers will be added at the end of a list. When prepend is True, it will be added in front of the list. This will habe an effect in the order the subscribers are called.
Raises:

SubscriptionError – if subscriber already subscribed

subscriptions

Property returning a tuple with all current subscribers

unsubscribe(subscriber: Subscriber) → None[source]

Unsubscribe the given subscriber

Parameters:subscriber – subscriber to unsubscribe
Raises:SubscriptionError – if subscriber is not subscribed (anymore)

StatefulPublisher

FromPolling