core.stream#

class immp.core.stream.PlugStream#

Bases: object

Message multiplexer, to read messages from multiple asynchronous generators in parallel.

Instances of this class are async-iterable – for each incoming message, a tuple is produced: the physical message received by the plug, a source message if originating from within the system, and a primary flag to indicate supplementary messages created when a system-sourced message can’t be represented in a single plug message.

Warning

As per Plug.stream(), only one iterator of this class should be used at once.

Yields:

(.SentMessage, .Message, bool) tuple – Messages received and processed by any connected plug.

add(*plugs)#

Connect plugs to the stream. When the stream is active, their Plug.stream() methods will be called to start collecting queued messages.

Parameters:

plugs (.Plug list) – New plugs to merge in.

remove(*plugs)#

Disconnect plugs from the stream. Their Plug.stream() tasks will be cancelled, and any last messages will be collected before removing.

Parameters:

plugs (.Plug list) – Active plugs to remove.