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

Method poll

crates/wasmtime/src/runtime/fiber.rs:958–986  ·  view source on GitHub ↗
(self: Pin<&mut Self>, cx: &mut Context<'_>)

Source from the content-addressed store, hash-verified

956 type Output = Result<Option<StoreFiber<'b>>>;
957
958 fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
959 let me = self.get_mut();
960
961 // SAFETY: We need to carry over this `cx` into our fiber's runtime for
962 // when it tries to poll sub-futures that are created. Doing this must
963 // be done unsafely, however, since `cx` is only alive for this one
964 // singular function call. Here we do a `transmute` to extend the
965 // lifetime of `Context` so it can be stored in our `Store`, and then we
966 // replace the current polling context with this one.
967 //
968 // The safety of this extension relies on never actually using
969 // `Context<'static>` with `'static` actually there, which should be
970 // satisfied by the users of this in the `BlockingContext` structure
971 // where the lifetime parameters there are always more constrained than
972 // they are here.
973 let cx: &mut Context<'static> = unsafe { change_context_lifetime(cx) };
974 let cx = NonNull::from(cx);
975
976 match resume_fiber(me.store, me.fiber.as_mut().unwrap(), Ok(cx)) {
977 Ok(Ok(())) => Poll::Ready(Ok(None)),
978 Ok(Err(e)) => Poll::Ready(Err(e)),
979 Err(StoreFiberYield::KeepStore) => Poll::Pending,
980 #[cfg(feature = "component-model-async")]
981 Err(StoreFiberYield::ReleaseStore) => match &me.on_release {
982 OnRelease::ReturnPending => Poll::Pending,
983 OnRelease::ReturnReady => Poll::Ready(Ok(me.fiber.take())),
984 },
985 }
986 }
987}
988
989impl Drop for FiberFuture<'_, '_> {

Callers 2

block_onMethod · 0.45
one_pollFunction · 0.45

Calls 8

change_context_lifetimeFunction · 0.85
fromFunction · 0.85
resume_fiberFunction · 0.85
OkFunction · 0.85
get_mutMethod · 0.45
unwrapMethod · 0.45
as_mutMethod · 0.45
takeMethod · 0.45

Tested by

no test coverage detected