Skip to content

Commit

Permalink
Do not set future if already done
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrattli committed Jan 18, 2024
1 parent 9b76cb3 commit 73074e0
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions expression/core/aiotools.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ def from_continuations(callback: Callbacks[_TSource]) -> Awaitable[_TSource]:
future: "Future[_TSource]" = asyncio.Future()

def done(value: _TSource) -> None:
future.set_result(value)
if not future.done():
future.set_result(value)

def error(err: Exception) -> None:
future.set_exception(err)
if not future.done():
future.set_exception(err)

def cancel(_: OperationCanceledError) -> None:
future.cancel()
if not future.done():
future.cancel()

callback(done, error, cancel)
return future
Expand Down

0 comments on commit 73074e0

Please sign in to comment.