evalit/runtime/object/
promise.rs1use std::{fmt, pin::Pin};
2
3use futures::FutureExt;
4
5use crate::{Object, Value};
6
7pub struct Promise(pub(crate) Pin<Box<dyn Future<Output = Value> + Send + 'static>>);
9
10impl Promise {
11 pub fn new(fut: impl Future<Output = Value> + Send + 'static) -> Self {
12 Self(Box::pin(fut))
13 }
14}
15
16impl Future for Promise {
17 type Output = Value;
18
19 fn poll(
20 mut self: std::pin::Pin<&mut Self>,
21 cx: &mut std::task::Context<'_>,
22 ) -> std::task::Poll<Self::Output> {
23 self.0.poll_unpin(cx)
24 }
25}
26
27impl fmt::Debug for Promise {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 f.debug_struct("Promise").finish()
30 }
31}
32
33impl Object for Promise {}