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>
impl<T> SyncAsyncFuture<T>
Sourcepub const fn ready(value: T) -> Self
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).
Sourcepub const fn empty() -> Self
pub const fn empty() -> Self
Create an empty ready result indicating no value is available.
Calling result() on this will return
[JunctureError::empty_channel()].
Sourcepub fn pending(
fut: impl Future<Output = Result<T, JunctureError>> + Send + 'static,
) -> Self
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).
Sourcepub async fn result(self) -> Result<T, JunctureError>
pub async fn result(self) -> Result<T, JunctureError>
Await the result, returning Ok(T) on success.
§Errors
- Returns [
JunctureError::empty_channel()] if the variant isReady(None)(no value available). - Returns the error from the inner future for the
Futurevariant.