Help with async FFI library #3534
-
Hello, I'm a beginner in rust and would like help with a question. I need to make a library that consumes a json api and I want to provide functions to be called from other applications, via FFI, however there is the problem of tokio::main. For the requests to be asynchronous I need the tokio runtime, but how to use it being that everything will be called in an external application? It would be unviable to start the runtime on every function call, and it would be great if I didn't need to create my own runtime. I thought about communication between processes, but I think it would not be viable either. I wonder if anyone has any idea how to do this: An asynchronous FFI rust library. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
There are many different answers to this question depending on how the non-Rust code needs to talk with the Rust code. The simplest way is to simply create a |
Beta Was this translation helpful? Give feedback.
There are many different answers to this question depending on how the non-Rust code needs to talk with the Rust code. The simplest way is to simply create a
tokio::runtime::Runtime
object, and use itsblock_on
method to transfer into an async region. By reusing theRuntime
object, you avoid creation of many new runtimes.