uniffi-rs icon indicating copy to clipboard operation
uniffi-rs copied to clipboard

Async runtime for function binding defined in UDL file

Open lyzkov opened this issue 6 months ago • 10 comments

I'm migrating from macros to UDL to decrease build time.

Is there any way to specify async runtime for an asynchronous function that has its definition in UDL marked with [Async] the same way I can do it with proc macro #[uniffi::export(async_runtime = "tokio")]?

[Error]
enum PingError {
  "IoError",
  "ParseError",
  "CustomError",
};

namespace ping_example {
  [Throws=PingError, Async]
  void start_listening();

  [Throws=PingError, Async]
  void dial_peer(string address);
};

From lib.rs:

/// Starts listening on all interfaces and a random, OS-assigned port.
pub async fn start_listening() -> Result<(), PingError> {
    // (...)
}

/// Dials the peer identified by the given multi-address.
pub async fn dial_peer(address: String) -> Result<(), PingError> {
    // (...)
}

Without async runtime specified I'm getting a runtime error:

Caught a panic calling rust code: "there is no reactor running, must be called from the context of a Tokio 1.x runtime"

lyzkov avatar Aug 16 '24 14:08 lyzkov