pub unsafe fn spawn_unchecked<F, S>(
future: F,
schedule: S,
) -> (Runnable, Task<F::Output>)
Expand description
Creates a new task without Send
, Sync
, and 'static
bounds.
This function is same as spawn()
, except it does not require Send
, Sync
, and
'static
on future
and schedule
.
Safety requirements:
- If
future
is notSend
, itsRunnable
must be used and dropped on the original thread. - If
future
is not'static
, borrowed variables must outlive itsRunnable
. - If
schedule
is notSend
andSync
, the task’sWaker
must be used and dropped on the original thread. - If
schedule
is not'static
, borrowed variables must outlive the task’sWaker
.
§Examples
// The future inside the task.
let future = async {
println!("Hello, world!");
};
// If the task gets woken up, it will be sent into this channel.
let (s, r) = flume::unbounded();
let schedule = move |runnable| s.send(runnable).unwrap();
// Create a task with the future and the schedule function.
let (runnable, task) = unsafe { async_task::spawn_unchecked(future, schedule) };