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
There's currently an "Asynchronous Operations" chapter which is meant to spin a a job off into the background and will periodically poll it to see if there's a result. We could accomplish this quite easily by using futures and a global CpuPool, with a TaskHandle struct which wraps a future and periodically polls.
The TaskHandle would have to be generic over any generic Task, meaning if we want to use it for FFI we'll want to use some sort of code generation (macro) for generating specialised functions for interacting with the background task.
I've done something like this before at work, so here's a gist to help get started. I was thinking it could use a Task trait similar to the following:
/// Spawn the task on a background thread, returning a `TaskHandle`. ////// # Safety////// This **consumes** the task, so it shouldn't be used once the task is spawned.#[no_mangle]pubunsafeextern"C"fnfoo_task_spawn(task:*mutFoo) -> TaskHandle<Foo>{ ...}/// Cancel a background task.#[no_mangle]pubunsafeextern"C"fnfoo_task_cancel(handle:*mutTaskHandle<Foo>){ ...}/// Wait until the task completes.////// # Safety////// This will consume the task handle and return a `Box<Task::Output>` (that you need/// to deallocate manually).#[no_mangle]pubunsafeextern"C"fnfoo_task_wait(handle:*mutTaskHandle<Foo>) -> *constFoo::Output{ ...}
...
The text was updated successfully, but these errors were encountered:
There's currently an "Asynchronous Operations" chapter which is meant to spin a a job off into the background and will periodically poll it to see if there's a result. We could accomplish this quite easily by using
futures
and a global CpuPool, with aTaskHandle
struct which wraps a future and periodically polls.The
TaskHandle
would have to be generic over any genericTask
, meaning if we want to use it for FFI we'll want to use some sort of code generation (macro) for generating specialised functions for interacting with the background task.I've done something like this before at work, so here's a gist to help get started. I was thinking it could use a
Task
trait similar to the following:Then the macro which generates FFI bindings for a particular
Task
implementation might look like this:Which might then generate:
The text was updated successfully, but these errors were encountered: