Pulsar is built on top of asyncio and therefore it uses all its asynchronous components and syntax. There are three, closely related, ways to create asynchronous components in pulsar.
Directly create a of
import asyncio o = asyncio.Future()
import pulsar o = pulsar.Future()
A coroutine, a generator which consumes values. For example:
async def my_async_generator(...): await something_but_dont_care_what_it_returns() ... bla = await something_and_care_what_it_returns() return await do_something(bla)
a coroutine is obtained by calling the coroutine function:
o = my_async_generator()
o is coroutine which has not yet started.
asyncio.Task, is a component which has been added to
pulsar asynchronous engine. It is created via the
when applied to a generator function:
from pulsar import ensure_future task = ensure_future(my_async_generator())
A task consumes a coroutine until the coroutine yield an asynchronous component
not yet done. When this appends, the task pauses and returns the control of execution.
Before it returns, it adds a
callback to the
on which the coroutine is blocked to resume the coroutine once the future
A task in this state is said to be suspended.