| 267 | /// F::Output T. |
| 268 | #[allow(unsafe_code)] |
| 269 | pub(crate) unsafe fn spawn_unchecked<F, T>(&self, fut: F) -> Task<T> |
| 270 | where |
| 271 | F: Future<Output = T>, |
| 272 | { |
| 273 | let this = self.clone(); |
| 274 | let schedule = move |runnable| this.inner.ready_list.lock().unwrap().push_back(runnable); |
| 275 | |
| 276 | // SAFETY: |
| 277 | // we're using this exactly like async_task::spawn_local, except that |
| 278 | // the schedule function is not Send or Sync, because Runnable is not |
| 279 | // Send or Sync. This is safe because wasm32-wasip2 is always |
| 280 | // single-threaded. |
| 281 | #[allow(unsafe_code)] |
| 282 | let (runnable, task) = unsafe { async_task::spawn_unchecked(fut, schedule) }; |
| 283 | self.inner.ready_list.lock().unwrap().push_back(runnable); |
| 284 | task |
| 285 | } |
| 286 | |
| 287 | /// Spawn a `Task` on the `Reactor`. |
| 288 | pub fn spawn<F, T>(&self, fut: F) -> Task<T> |