xref: /libuv/docs/src/async.rst (revision 707dd7f1)
1
2.. _async:
3
4:c:type:`uv_async_t` --- Async handle
5=====================================
6
7Async handles allow the user to "wakeup" the event loop and get a callback
8called from another thread.
9
10
11Data types
12----------
13
14.. c:type:: uv_async_t
15
16    Async handle type.
17
18.. c:type:: void (*uv_async_cb)(uv_async_t* handle)
19
20    Type definition for callback passed to :c:func:`uv_async_init`.
21
22
23Public members
24^^^^^^^^^^^^^^
25
26N/A
27
28.. seealso:: The :c:type:`uv_handle_t` members also apply.
29
30
31API
32---
33
34.. c:function:: int uv_async_init(uv_loop_t* loop, uv_async_t* async, uv_async_cb async_cb)
35
36    Initialize the handle. A NULL callback is allowed.
37
38    :returns: 0 on success, or an error code < 0 on failure.
39
40    .. note::
41        Unlike other handle initialization  functions, it immediately starts the handle.
42
43.. c:function:: int uv_async_send(uv_async_t* async)
44
45    Wake up the event loop and call the async handle's callback.
46
47    :returns: 0 on success, or an error code < 0 on failure.
48
49    .. note::
50        It's safe to call this function from any thread. The callback will be called on the
51        loop thread.
52
53    .. note::
54        :c:func:`uv_async_send` is `async-signal-safe <https://man7.org/linux/man-pages/man7/signal-safety.7.html>`_.
55        It's safe to call this function from a signal handler.
56
57    .. warning::
58        libuv will coalesce calls to :c:func:`uv_async_send`, that is, not every call to it will
59        yield an execution of the callback. For example: if :c:func:`uv_async_send` is called 5
60        times in a row before the callback is called, the callback will only be called once. If
61        :c:func:`uv_async_send` is called again after the callback was called, it will be called
62        again.
63
64.. seealso::
65    The :c:type:`uv_handle_t` API functions also apply.
66