Skip to main content

dope_core/executor/task/context/
pollcall.rs

1use core::pin::Pin;
2
3use crate::executor::task::context::{self, Context};
4
5/// Exact, single-use admission for polling one pinned fiber.
6/// It is constructed only after consuming one application-work credit and
7/// cannot be retagged to a different fiber type.
8pub struct PollCall<'call, 'turn, 'd: 'turn, F> {
9    pub(in crate::executor::task) fiber: Pin<&'call mut F>,
10    pub(in crate::executor::task) context: &'call mut Context<'turn, 'd>,
11}
12
13impl<'call, 'turn, 'd: 'turn, F> PollCall<'call, 'turn, 'd, F> {
14    pub(in crate::executor) fn from_root(
15        fiber: Pin<&'call mut F>,
16        context: &'call mut Context<'turn, 'd>,
17    ) -> Self {
18        Self { fiber, context }
19    }
20
21    pub fn into_fiber(self) -> Pin<&'call mut F> {
22        self.fiber
23    }
24
25    pub fn into_context(self) -> &'call mut Context<'turn, 'd> {
26        self.context
27    }
28
29    pub fn into_parts(self) -> (Pin<&'call mut F>, &'call mut Context<'turn, 'd>) {
30        (self.fiber, self.context)
31    }
32
33    /// Retains this call's credit for one child task while lending the owner
34    /// for its pinned projection and state transition.
35    pub fn into_admit(self) -> (Pin<&'call mut F>, context::raw::Admission<'call, 'turn, 'd>) {
36        (
37            self.fiber,
38            context::raw::Admission {
39                context: self.context,
40            },
41        )
42    }
43}