From 2b7419a77245c20a569b991f2ed1c2120db6e627 Mon Sep 17 00:00:00 2001 From: Peter <49501366+ZeroIntensity@users.noreply.github.com> Date: Wed, 1 May 2024 10:40:21 -0400 Subject: [PATCH] Update adding_coros.md --- docs/adding_coros.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/adding_coros.md b/docs/adding_coros.md index 103e62f..27fe80b 100644 --- a/docs/adding_coros.md +++ b/docs/adding_coros.md @@ -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; +} +``` + +