surrealdb_core/sql/
future.rs1use crate::dbs::Options;
2use crate::doc::CursorDoc;
3use crate::err::Error;
4use crate::sql::block::Block;
5use crate::sql::value::Value;
6use crate::{ctx::Context, dbs::Futures};
7use reblessive::tree::Stk;
8use revision::revisioned;
9use serde::{Deserialize, Serialize};
10use std::fmt;
11
12pub(crate) const TOKEN: &str = "$surrealdb::private::sql::Future";
13
14#[revisioned(revision = 1)]
15#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
16#[serde(rename = "$surrealdb::private::sql::Future")]
17#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
18#[non_exhaustive]
19pub struct Future(pub Block);
20
21impl From<Value> for Future {
22 fn from(v: Value) -> Self {
23 Future(Block::from(v))
24 }
25}
26
27impl Future {
28 pub(crate) async fn compute(
30 &self,
31 stk: &mut Stk,
32 ctx: &Context,
33 opt: &Options,
34 doc: Option<&CursorDoc>,
35 ) -> Result<Value, Error> {
36 match opt.futures {
38 Futures::Enabled => stk.run(|stk| self.0.compute(stk, ctx, opt, doc)).await?.ok(),
39 _ => Ok(self.clone().into()),
40 }
41 }
42}
43
44impl fmt::Display for Future {
45 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
46 write!(f, "<future> {}", self.0)
47 }
48}