Skip to main content

TasksAdapter

Struct TasksAdapter 

Source
pub struct TasksAdapter { /* private fields */ }
Expand description

Typed wrapper around CortexAdapter<TasksState> that exposes domain-level operations (create, rename, complete, delete) and hides the EventMeta + postcard plumbing.

Implementations§

Source§

impl TasksAdapter

Source

pub async fn open( redex: &Redex, origin_hash: u64, ) -> Result<Self, CortexAdapterError>

Open the tasks adapter against a Redex manager.

Uses TASKS_CHANNEL ("cortex/tasks"). Replays the full history into state on open; subsequent events are appended to the same channel.

async because the constructor awaits the fold task’s catch-up before returning: the inner WatermarkingFold observes every replayed event’s EventMeta and advances app_seq past any pre-existing same-origin seq_or_ts, so the first ingest_typed after open cannot collide with an already-stored event.

Source

pub async fn open_with_config( redex: &Redex, origin_hash: u64, redex_config: RedexFileConfig, ) -> Result<Self, CortexAdapterError>

Like Self::open but with a caller-supplied RedexFileConfig (useful for persistent: true or custom retention).

Source

pub fn create( &self, id: TaskId, title: impl Into<String>, now_ns: u64, ) -> Result<u64, CortexAdapterError>

Create a new task. Returns the RedEX seq of the append.

Source

pub fn rename( &self, id: TaskId, new_title: impl Into<String>, now_ns: u64, ) -> Result<u64, CortexAdapterError>

Rename an existing task. No-op at fold time if id is unknown.

Source

pub fn complete( &self, id: TaskId, now_ns: u64, ) -> Result<u64, CortexAdapterError>

Mark a task completed. No-op at fold time if id is unknown.

Source

pub fn delete(&self, id: TaskId) -> Result<u64, CortexAdapterError>

Delete a task. No-op at fold time if id is unknown.

Source

pub fn state(&self) -> Arc<RwLock<TasksState>>

Read-only access to the materialized state.

Source

pub fn count(&self) -> usize

Total task count in the current state. Cheap; acquires the state read lock briefly. Matches the Node/Python SDK surface.

Source

pub async fn wait_for_seq(&self, seq: u64) -> Result<(), Option<u64>>

Block until every event up through seq has been folded. Returns Err(folded) if the fold task stopped before reaching seq; see CortexAdapter::wait_for_seq for the stop-vs-success rationale.

Source

pub async fn wait_for_token( &self, token: WriteToken, deadline: Duration, ) -> Result<(), WaitForTokenError>

Block until the fold task has processed every event up through token.seq, or deadline elapses. Read-your-writes wait: a writer who got token from this origin’s ingest path can call this to make sure the local fold has caught up before reading state.

Rejects tokens issued for a different origin with WaitForTokenError::WrongOrigin — protects against the causal_tokens.get(other_origin).wait(my_token) aliasing failure where a wait on this adapter would never resolve because the targeted seq belongs to someone else’s chain.

Source

pub fn poll_for_token(&self, token: WriteToken) -> Result<(), WaitForTokenError>

Non-blocking RYW poll. Synchronously checks origin binding + the applied watermark and returns without scheduling any wait. Use for “is my write visible yet?” queries where the caller doesn’t want to block:

  • Ok(()) — the write is observable; subsequent reads see it.
  • Err(WaitForTokenError::WrongOrigin {..}) — the token’s origin_hash doesn’t match this adapter’s bound origin.
  • Err(WaitForTokenError::FoldStopped {..}) — the fold task has stopped before reaching the target seq; the write will never become observable.
  • Err(WaitForTokenError::Timeout) — not yet (try again later).

Mirrors the FFI’s timeout_ms == 0 shape so every binding can expose a “poll, don’t wait” entry point with consistent semantics. No semaphore permit is taken; QueueFull is not reachable on this path.

Source

pub fn close(&self) -> Result<(), CortexAdapterError>

Close the adapter. See CortexAdapter::close.

Source

pub fn is_running(&self) -> bool

True if the fold task is currently running.

Source

pub fn as_cortex(&self) -> &CortexAdapter<TasksState>

Access the wrapped CortexAdapter for cases that need the lower-level surface.

Source

pub fn origin_hash(&self) -> u64

Origin hash this adapter is bound to. Stamped on every outgoing EventMeta; tokens with a different origin reject at wait_for_token.

Source

pub fn watch(&self) -> TasksWatcher

Start building a reactive watcher. See TasksWatcher::stream for emission semantics (initial + deduplicated on filter-result change).

Source

pub fn snapshot_and_watch( &self, watcher: TasksWatcher, ) -> (Vec<Task>, Pin<Box<dyn Stream<Item = Vec<Task>> + Send + 'static>>)

One-shot combo: a snapshot of the current filter result PLUS a stream that emits every subsequent change to that filter. The stream skips the initial emission so the caller doesn’t see the snapshot twice — the snapshot is the initial state; the stream carries deltas from there forward.

Useful for UI-style consumers: “paint what’s there now, then react to changes” without a manual dedup against the first emission.

Source

pub fn snapshot(&self) -> Result<(Vec<u8>, Option<u64>), CortexAdapterError>

Capture a snapshot suitable for restore. Returns (state_bytes, last_seq) — persist both together.

Source

pub async fn open_from_snapshot( redex: &Redex, origin_hash: u64, state_bytes: &[u8], last_seq: Option<u64>, ) -> Result<Self, CortexAdapterError>

Open the tasks adapter from a snapshot, skipping replay of events up through last_seq.

See Self::open for why this is async.

Source

pub async fn open_from_snapshot_with_config( redex: &Redex, origin_hash: u64, redex_config: RedexFileConfig, state_bytes: &[u8], last_seq: Option<u64>, ) -> Result<Self, CortexAdapterError>

Like Self::open_from_snapshot but with a caller-supplied RedexFileConfig (e.g. for persistent: true).

Trait Implementations§

Source§

impl Debug for TasksAdapter

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<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> Same for T

Source§

type Output = T

Should always be Self
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<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