View source on GitHub |
An event demultiplexer for QuantumRunStreamResponses, as part of the async reactor pattern.
cirq_google.engine.stream_manager.ResponseDemux() -> None 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
publish( response: quantum.QuantumRunStreamResponse ) -> None 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
publish_exception( exception: BaseException ) -> None Publishes an exception to all outstanding futures.
subscribe
subscribe( message_id: str ) -> asyncio.Future 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. |
View source on GitHub