| 330 | static WAKERS: Mutex<Vec<(io::poll::Pollable, Waker)>> = Mutex::new(Vec::new()); |
| 331 | |
| 332 | pub fn run<T>(future: impl Future<Output = T>) -> T { |
| 333 | futures::pin_mut!(future); |
| 334 | |
| 335 | struct DummyWaker; |
| 336 | |
| 337 | impl Wake for DummyWaker { |
| 338 | fn wake(self: Arc<Self>) {} |
| 339 | } |
| 340 | |
| 341 | let waker = Arc::new(DummyWaker).into(); |
| 342 | |
| 343 | loop { |
| 344 | match future.as_mut().poll(&mut Context::from_waker(&waker)) { |
| 345 | Poll::Pending => { |
| 346 | let mut new_wakers = Vec::new(); |
| 347 | |
| 348 | let wakers = mem::take::<Vec<_>>(&mut WAKERS.lock().unwrap()); |
| 349 | |
| 350 | assert!(!wakers.is_empty()); |
| 351 | |
| 352 | let pollables = wakers |
| 353 | .iter() |
| 354 | .map(|(pollable, _)| pollable) |
| 355 | .collect::<Vec<_>>(); |
| 356 | |
| 357 | let mut ready = vec![false; wakers.len()]; |
| 358 | |
| 359 | for index in io::poll::poll(&pollables) { |
| 360 | ready[usize::try_from(index).unwrap()] = true; |
| 361 | } |
| 362 | |
| 363 | for (ready, (pollable, waker)) in ready.into_iter().zip(wakers) { |
| 364 | if ready { |
| 365 | waker.wake() |
| 366 | } else { |
| 367 | new_wakers.push((pollable, waker)); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | *WAKERS.lock().unwrap() = new_wakers; |
| 372 | } |
| 373 | Poll::Ready(result) => break result, |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | pub fn outgoing_body(body: OutgoingBody) -> impl Sink<Vec<u8>, Error = Error> { |
| 379 | struct Outgoing(Option<(OutputStream, OutgoingBody)>); |