Skip to main content

SyncAsyncFuture

Enum SyncAsyncFuture 

Source
pub enum SyncAsyncFuture<T> {
    Ready(Option<T>),
    Future(BoxFuture<'static, Result<T, JunctureError>>),
}
Expand description

A task result that may be synchronously ready or asynchronously computed.

In the functional API (@task/@entrypoint), results are wrapped as SyncAsyncFuture. Callers use .result().await uniformly regardless of whether the underlying computation was synchronous (cache hit) or asynchronous (computation required).

§Type Parameters

  • T - The success value type produced by this future

§Examples

use juncture_core::pregel::types::SyncAsyncFuture;

// Synchronous (cache hit)
let ready = SyncAsyncFuture::ready(42);
assert!(ready.is_ready());
assert_eq!(ready.result().await?, 42);

// Asynchronous (needs computation)
let pending = SyncAsyncFuture::pending(async { Ok(99) });
assert!(!pending.is_ready());
assert_eq!(pending.result().await?, 99);

Variants§

§

Ready(Option<T>)

Synchronous result (e.g., cache hit).

§

Future(BoxFuture<'static, Result<T, JunctureError>>)

Asynchronous result that resolves to Result<T, JunctureError>.

Implementations§

Source§

impl<T> SyncAsyncFuture<T>

Source

pub const fn ready(value: T) -> Self

Create a synchronous ready result with a value.

Use this when the result is already available (e.g., cache hit).

Source

pub const fn empty() -> Self

Create an empty ready result indicating no value is available.

Calling result() on this will return [JunctureError::empty_channel()].

Source

pub fn pending( fut: impl Future<Output = Result<T, JunctureError>> + Send + 'static, ) -> Self

Create an asynchronous result from a future that resolves to Result<T, JunctureError>.

Use this when the result requires computation (e.g., cache miss, network call, or LLM invocation).

Source

pub async fn result(self) -> Result<T, JunctureError>

Await the result, returning Ok(T) on success.

§Errors
  • Returns [JunctureError::empty_channel()] if the variant is Ready(None) (no value available).
  • Returns the error from the inner future for the Future variant.
Source

pub const fn is_ready(&self) -> bool

Check if the result is synchronously available.

Returns true for the Ready variant (regardless of whether the inner value is Some or None), and false for Future.

Trait Implementations§

Source§

impl<T: Debug> Debug for SyncAsyncFuture<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> From<T> for SyncAsyncFuture<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for SyncAsyncFuture<T>

§

impl<T> !Sync for SyncAsyncFuture<T>

§

impl<T> !UnwindSafe for SyncAsyncFuture<T>

§

impl<T> Freeze for SyncAsyncFuture<T>
where T: Freeze,

§

impl<T> Send for SyncAsyncFuture<T>
where T: Send,

§

impl<T> Unpin for SyncAsyncFuture<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for SyncAsyncFuture<T>
where T: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more