| 168 | #[cfg(not(tokio_unstable))] |
| 169 | #[track_caller] |
| 170 | pub fn spawn<Fut, Name, NameClosure>(_nc: NameClosure, future: Fut) -> JoinHandle<Fut::Output> |
| 171 | where |
| 172 | Name: AsRef<str>, |
| 173 | NameClosure: FnOnce() -> Name, |
| 174 | Fut: Future + Send + 'static, |
| 175 | Fut::Output: Send + 'static, |
| 176 | { |
| 177 | // Box the future so tokio's task machinery is monomorphized over |
| 178 | // `Pin<Box<dyn Future<Output = Fut::Output> + Send>>` per output type, |
| 179 | // rather than over every distinct future type at every call site. |
| 180 | let future: Pin<Box<dyn Future<Output = Fut::Output> + Send>> = Box::pin(future); |
| 181 | #[allow(clippy::disallowed_methods)] |
| 182 | JoinHandle::new(tokio::spawn(future)) |
| 183 | } |
| 184 | |
| 185 | /// Spawns a new asynchronous task with a name. |
| 186 | /// |