Title: Theory / Unimportant / CS / Programming / Python / Async / Future
Tags: automatedNewLineAfterCommaSpace
On every note of this deck, unless a note says otherwise:
Page: https://docs.python.org/3.10/library/asyncio-future.html

Typ: asyncio.Future
Meaning: low-level awaitable object that represents an eventual result of an asynchronous operation.
Page: https://docs.python.org/3.10/library/asyncio-task.html
Language: Python
Subtype of: awaitable

Instruction: asyncio.isfuture(obj)
Language: python
Returns: Whether an obj is a future, task or future-like

Name: A future-like object
Definition: An object with a _asyncio_future_blocking attribute.
Page: https://docs.python.org/3.10/library/asyncio-future.html
Chapter: python

Instruction: asyncio.ensure_future(
  obj,
  *,
  loop=None
)
Chapter: python
Returns: obj, if it is a future. Task wrapping obj if it is awaitable
Intuition: prefer create_task
Exception: TypeError if org is neither future nor awaitable

Instruction: asyncio.wrap_future(
  concurrent_future,
  *,
  loop=None
)
Chapter: python
Returns: concurrent_future, as an asyncio.Future
Variables: concurrent.futures.Future concurrent_future

Instruction: future.set_result()
Effect: Mark the Future as done and set its result.
Chapter: python
Variables: future: asyncio.Future
Exception: Raises a InvalidStateError error if the Future is already done.

Instruction: future.set_exception()
Effect: Mark the Future as done and set an exception.
Chapter: python
Variables: future: asyncio.Future
Exception: Raises a InvalidStateError error if the Future is already done.

Instruction: taskOrFuture.done()
Chapter: python
Returns: Whether taskOrFuture is done
Variables: future: asyncio.Future

Instruction: future.get_loop()
Chapter: python
Returns: The event loop the future object is bound to
Variables: future: asyncio.Future

Question: Difference between concurrent.futures.Future and asyncio.Future
Answer: - unlike asyncio Futures, concurrent.futures.Future instances cannot be awaited.
Page: https://docs.python.org/3.10/library/asyncio-future.html
Chapter: python
Answer2: - asyncio.Future.result() and asyncio.Future.exception() do not accept the timeout argument.
Answer3: - asyncio.Future.result() and asyncio.Future.exception() raise an InvalidStateError exception when the Future is not done.
Answer4: - Callbacks registered with asyncio.Future.add_done_callback() are not called immediately. They are scheduled with loop.call_soon() instead.
Answer5: - asyncio Future is not compatible with the concurrent.futures.wait() and concurrent.futures.as_completed() functions.
Answer6: - asyncio.Future.cancel() accepts an optional msg argument, but concurrent.futures.cancel() does not.

Question: transport
Answer: todo
Page: https://docs.python.org/3.10/library/asyncio-protocol.html
Chapter: python