Function async_task::spawn_unchecked
source · 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
- If
futureis notSend, itsRunnablemust be used and dropped on the original thread. - If
futureis not'static, borrowed variables must outlive itsRunnable. - If
scheduleis notSendandSync, all instances of theRunnable’sWakermust be used and dropped on the original thread. - If
scheduleis not'static, borrowed variables must outlive all instances of theRunnable’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) };