Synchronous ComponentsΒΆ

AsyncObject are used everywhere in pulsar. These objects expose the _loop attribute as discussed in the design documentation.

Normally, the _loop is a running event loop controlled by an Actor. In this case, all operations which requires the loop, are carried out asynchronously as one would expect.

However, sometimes it can be useful to have AsyncObject which behaves in a synchronous fashion. Pulsar achieves this by using a new event loop for that object. For example, this statement creates a synchronous HttpClient:

>>> from pulsar import new_event_loop
>>> from pulsar.apps import http
>>> client = http.HttpClient(loop=new_event_loop())
>>> client._loop.is_running()
False

You can now execute synchronous requests:

>>> response = client.get('https://pypi.python.org/pypi/pulsar/json')

Under the hood, pulsar treats a synchronous request exactly in the same way as an asynchronous one with the only difference that the event loop is always used via the run_until_complete() method to wait for the response to be available.