Skip to content

Commit 77dcd84

Browse files
author
Traktormaster
committed
Update the readme
1 parent b1fe334 commit 77dcd84

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ ignoring the cancellation is critical to the application it may not be suitable
1616

1717
Using this implementation, in case both conditions occur at the same time a subclassed `CancelledError` will be
1818
raised which also contains the result of the future. The caller code must catch this exception and handle the
19-
result if it is important. Otherwise it can be used the same way as the builtin `wait_for`.
19+
result if it is important. Otherwise, it can be used the same way as the builtin `wait_for`.
20+
21+
If the caller prefers to handle the race-condition with a callback, the `race_handler` argument may be provided.
22+
It will be called with the result of the future when the waiter task is being cancelled. Even if this is provided,
23+
the special error will be raised in the place of a normal CancelledError.
2024

2125
NOTE: `CancelledWithResultError` is limited to the coroutine `wait_for` is invoked from!
2226
If this `wait_for` is wrapped in tasks those will not propagate the special exception, but raise their own
2327
`CancelledError` instances.
2428

2529
# Install & usage
26-
A source distribution is available on PyPI:
30+
A package is available on PyPI:
2731

2832
```console
2933
$ python -m pip install wait_for2
@@ -46,4 +50,8 @@ except wait_for2.CancelledWithResultError as e:
4650
# NOTE: e.result could be an exception raised by the task; handling or ignoring it is up to the user code here
4751
await process_result(e.result)
4852
raise asyncio.CancelledError()
53+
54+
# alternatively with a callback:
55+
await process_result(await wait_for2.wait_for(task, 5.0, race_handler=process_result))
56+
4957
```

wait_for2/impl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async def wait_for(fut, timeout, *, loop=None, race_handler=None):
6060
result if it is important. Otherwise it can be used the same way as the builtin wait_for.
6161
6262
If the caller prefers to handle the race-condition with a callback, the `race_handler` argument may be provided.
63-
It will be called with the result of the future when the waiter task is being cancelled. Even if this is provided
63+
It will be called with the result of the future when the waiter task is being cancelled. Even if this is provided,
6464
the special error will be raised in the place of a normal CancelledError.
6565
6666
NOTE: CancelledWithResultError is limited to the coroutine wait_for is invoked from!

0 commit comments

Comments
 (0)