MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / run

Function run

crates/test-programs/src/bin/p2_api_proxy_streaming.rs:332–376  ·  view source on GitHub ↗
(future: impl Future<Output = T>)

Source from the content-addressed store, hash-verified

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)>);

Callers 1

handleMethod · 0.70

Calls 11

pollFunction · 0.70
newFunction · 0.50
pollMethod · 0.45
as_mutMethod · 0.45
unwrapMethod · 0.45
lockMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45
into_iterMethod · 0.45
wakeMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected