Macro ffi_helpers::export_task [] [src]

macro_rules! export_task {
    ($( #[$attr:meta] )* Task: $Task:ty; spawn: $spawn:ident; $( $tokens:tt )*) => { ... };
    ($( #[$attr:meta] )* Task: $Task:ty; poll: $poll:ident; $( $tokens:tt )*) => { ... };
    ($( #[$attr:meta] )* Task: $Task:ty; handle_destroy: $handle_destructor:ident; $( $tokens:tt )*) => { ... };
    ($( #[$attr:meta] )* Task: $Task:ty; result_destroy: $result_destroy:ident; $( $tokens:tt )*) => { ... };
    ($( #[$attr:meta] )* Task: $Task:ty; wait: $wait:ident; $( $tokens:tt )*) => { ... };
    ($( #[$attr:meta] )* Task: $Task:ty; cancel: $cancel:ident; $( $tokens:tt )*) => { ... };
    ($( #[$attr:meta] )* Task: $Task:ty; cancelled: $cancelled:ident; $( $tokens:tt )*) => { ... };
    ($( #[$attr:meta] )* Task: $Task:ty;) => { ... };
}

Convenience macro to define the FFI bindings for working with a Task.

This is implemented as an incremental TT muncher which lets you define the functions you'll need. These are:

  • spawn: The function for spawning a task on a background thread, returning a TaskHandle
  • poll: A function for receiving the result if it's available
  • wait: Block the current thread until we get either a result or an error
  • cancel: Cancel the background task
  • cancelled: Has the task already been cancelled?
  • result_destroy: A destructor for the task's result
  • handle_destroy: A destructor for the TaskHandle, for cleaning up the task once you're done with it

You'll always need to provide the concrete Task type in the macro's first "argument".