Event streams

Event streams are covered by carb.events plugin and carb::events::IEvents Carbonite interface. The goal of event streams is to provide means to move data around using the generalized interface in a thread safe manner, and also act as a way to synchronize the logic.

API/design overview

The singleton IEvents interface is used to create IEventStream objects. Whenever an event is being pushed into an event stream, the immediate callback is triggered, and the event stream stores the event in the internal event queue. Then, events can be popped from the queue one by one, or all at once (also called pump), and at this point deferred callbacks are triggered. Event stream owner typically controls where this pumping is happening.

Event consumers can subscribe to both immediate (push) and deferred (pop) callbacks. Subcription functions create ISubscription class, which usually unsubscribes automatically upon destruction. Callbacks are wrapped into IEventListener class that allows for context binding to the subscription, and upon triggering, the callback is triggered with the IEvent passed as parameter, this parameter describes the event which triggered the callback. IEvent contains event type, sender id and custom payload, which is stored as carb.dictionary item.