cirq_google.engine.stream_manager.ResponseDemux

An event demultiplexer for QuantumRunStreamResponses, as part of the async reactor pattern.

A caller can subscribe to the response matching a provided message ID. Only a single caller may subscribe to each ID.

Another caller can subsequently publish a response. The future held by the subscriber with the matching message ID will then be fulfilled.

A caller can also publish an exception to all subscribers.

Methods

publish

View source

Makes the response available to the subscriber with the matching message ID.

The subscriber is unsubscribed afterwards.

If there are no subscribers waiting for the response, nothing happens.

publish_exception

View source

Publishes an exception to all outstanding futures.

subscribe

View source

Subscribes to the QuantumRunStreamResponse with a matching ID.

There should only be one subscriber per message ID.

Returns
A future for the response, to be fulfilled when publish is called.

Raises
ValueError when trying to subscribe to a message_id which already has a subscriber.