You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/manual/src/futures.md
+8-2Lines changed: 8 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,8 +4,6 @@ UniFFI supports exposing async Rust functions over the FFI. It can convert a Rus
4
4
5
5
Check out the [examples](https://github.com/mozilla/uniffi-rs/tree/main/examples/futures) or the more terse and thorough [fixtures](https://github.com/mozilla/uniffi-rs/tree/main/fixtures/futures).
6
6
7
-
Note that currently async functions are only supported by proc-macros, UDL support is being planned in https://github.com/mozilla/uniffi-rs/issues/1716.
8
-
9
7
## Example
10
8
11
9
This is a short "async sleep()" example:
@@ -34,6 +32,14 @@ if __name__ == '__main__':
34
32
asyncio.run(main())
35
33
```
36
34
35
+
Async functions can also be defined in UDL:
36
+
```idl
37
+
namespace example {
38
+
[Async]
39
+
string say_after(u64 ms, string who);
40
+
}
41
+
```
42
+
37
43
This code uses `asyncio` to drive the future to completion, while our exposed function is used with `await`.
38
44
39
45
In Rust `Future` terminology this means the foreign bindings supply the "executor" - think event-loop, or async runtime. In this example it's `asyncio`. There's no requirement for a Rust event loop.
0 commit comments