Skip to content

Commit

Permalink
Update adding_coros.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroIntensity authored May 1, 2024
1 parent 1bada5c commit 2b7419a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/adding_coros.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,27 @@ spam(PyObject *self, PyObject *args)
```
This would be equivalent to `await foo` from Python.
## Return Values
You can set a return value (the thing that `await c_func()` will evaluate to) via `awaitable_set_result` (`PyAwaitable_SetResult` in the Python prefixes). By default, the return value is `None`.
!!! warning
`awaitable_set_result` can *only* be called from a callback. Otherwise, a `TypeError` is raised.
For example:
```c
static int
callback(PyObject *awaitable, PyObject *result)
{
if (awaitable_set_result(awaitable, result) < 0)
return -1;
// Do something with the result...
return 0;
}
```


0 comments on commit 2b7419a

Please sign in to comment.