From 221f71013e1a3c1c698fefd52aa81beb11fd2a39 Mon Sep 17 00:00:00 2001 From: "uniffi-docs[bot]" Date: Mon, 23 Dec 2024 16:42:02 +0000 Subject: [PATCH] Deployed 1c002fa35 to next with MkDocs 1.6.0 and mike 2.1.1 --- next/internals/async.html | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/next/internals/async.html b/next/internals/async.html index f5599b562..d74db425e 100644 --- a/next/internals/async.html +++ b/next/internals/async.html @@ -1885,7 +1885,7 @@

Rust Async functions

Rust async functions are implemplemented by wrapping the Future into a uniffi::RustFuture struct and providing scaffolding functions so that the foreign bindings can drive the future to completion.

-
sequenceDiagram
+
sequenceDiagram
   participant User as User code
   participant Foreign as Foreign Language Bindings
   participant Rust as Rust Scaffolding
@@ -1902,8 +1902,7 @@ 

Rust Async functions

Foreign->>+Rust: call RustFuture complete fn Rust-->>-Foreign: return result Foreign->>Rust: call RustFuture free fn - Foreign-->>-User: return from async function -
+ Foreign-->>-User: return from async function

For each async function, UniFFI generates 4 scaffolding functions: * A scaffolding function that returns a RustFuture handle * rust_future_poll to poll the future @@ -1937,7 +1936,7 @@

Why not have rust_

Foreign async callback methods

Async callback/trait interface methods are the way that Rust makes async calls across the FFI. These are implemented using a callback, which makes them quite a bit simpler than their counterparts.

-
sequenceDiagram
+
sequenceDiagram
   participant User as User code
   participant Rust as Rust Scaffolding
   participant Foreign as Foreign Language Bindings
@@ -1947,8 +1946,7 @@ 

Foreign async callback methods

Rust-->>-User: return oneshot::Receiver Foreign->>Rust: invoke callback, pass back oneshot::Sender pointer - Note over Rust: send callback result to the oneshot::Sender -
+ Note over Rust: send callback result to the oneshot::Sender

The UniFFI generated code for an async trait method performs these steps:

  • Create a oneshot::Channel (see oneshot crate for how these work, although we don't currently depend on that crate).
  • @@ -1980,7 +1978,7 @@

    Can you real Furthermore, let's stipulate that the deserialization/validation is slow enough to be considered blocking. To manage this, the Rust library also depends on a (synchronous) callback interface that runs a task in a worker queue where blocking is allowed. Here's how the async API call could be handled:

    -
    sequenceDiagram
    +
    sequenceDiagram
       participant AsyncRust as Async Rust code
       participant SyncRust as Sync Rust code
       participant WorkerQueue as Work Queue Callback Interface
    @@ -1995,8 +1993,7 @@ 

    Can you real Note over AsyncRust: await oneshot channel WorkerQueue->>SyncRust: Run task (in background thread) SyncRust-->>AsyncRust: Send deserialized response via oneshot channel - AsyncRust-->>-Foreign: Return API result -

    + AsyncRust-->>-Foreign: Return API result
    • Action in this sequence diagram represents calling an async Rust function or async callback interface method, see the above diagrams for details.
    • The dotted lines show how the data is passed around during the async call.