uniffi-rs
uniffi-rs copied to clipboard
Foreign BackgroundQueue type
A common pattern we use in application-services is to run SQLite queries using a foreign-managed task queue (Dispatchers.IO on Kotlin, DispatchQueue on Swift, etc). Could UniFFI support this as a first-class type?
This would require:
- Moving it across the FFI (only supporting Foreign -> Rust is probably fine)
- Adding way to execute Rust synchronous code using the foreign DispatchQueue in two modes:
- async mode where you await the result
- fire-and-forget mode where you just want the code to run and don't care about the result.
I think BackgroundQueue is a nicer name than DispatchQueue, since the feature is really about running tasks in a background thread. I feel like there could be a better name though, open to any suggestions.
"background thread" implies "low priority thread" to me, which I don't think is the actual intent. The actual use-cases here tend to be more about thread blocking than thread priority. I was going to suggest something like TaskQueue, but depending on the content the Task part of that might itself carry baggage. WorkQueue? But I don't think it matters that much though.
You're right, it really is about blocking more than anything. tokio separates their threads into "worker threads" and "blocking threads". What about BlockingQueue or BlockingTaskQueue?
using the same terminology as tokio is certainly appealing!