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
impl TasksAdapter
Sourcepub async fn open(
redex: &Redex,
origin_hash: u64,
) -> Result<Self, CortexAdapterError>
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.
Sourcepub async fn open_with_config(
redex: &Redex,
origin_hash: u64,
redex_config: RedexFileConfig,
) -> Result<Self, CortexAdapterError>
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).
Sourcepub fn create(
&self,
id: TaskId,
title: impl Into<String>,
now_ns: u64,
) -> Result<u64, CortexAdapterError>
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.
Sourcepub fn rename(
&self,
id: TaskId,
new_title: impl Into<String>,
now_ns: u64,
) -> Result<u64, CortexAdapterError>
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.
Sourcepub fn complete(
&self,
id: TaskId,
now_ns: u64,
) -> Result<u64, CortexAdapterError>
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.
Sourcepub fn delete(&self, id: TaskId) -> Result<u64, CortexAdapterError>
pub fn delete(&self, id: TaskId) -> Result<u64, CortexAdapterError>
Delete a task. No-op at fold time if id is unknown.
Sourcepub fn count(&self) -> usize
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.
Sourcepub async fn wait_for_seq(&self, seq: u64) -> Result<(), Option<u64>>
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.
Sourcepub async fn wait_for_token(
&self,
token: WriteToken,
deadline: Duration,
) -> Result<(), WaitForTokenError>
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.
Sourcepub fn poll_for_token(&self, token: WriteToken) -> Result<(), WaitForTokenError>
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’sorigin_hashdoesn’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.
Sourcepub fn close(&self) -> Result<(), CortexAdapterError>
pub fn close(&self) -> Result<(), CortexAdapterError>
Close the adapter. See CortexAdapter::close.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
True if the fold task is currently running.
Sourcepub fn as_cortex(&self) -> &CortexAdapter<TasksState>
pub fn as_cortex(&self) -> &CortexAdapter<TasksState>
Access the wrapped CortexAdapter for cases that need the
lower-level surface.
Sourcepub fn origin_hash(&self) -> u64
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.
Sourcepub fn watch(&self) -> TasksWatcher
pub fn watch(&self) -> TasksWatcher
Start building a reactive watcher. See
TasksWatcher::stream for emission semantics (initial +
deduplicated on filter-result change).
Sourcepub fn snapshot_and_watch(
&self,
watcher: TasksWatcher,
) -> (Vec<Task>, Pin<Box<dyn Stream<Item = Vec<Task>> + Send + 'static>>)
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.
Sourcepub fn snapshot(&self) -> Result<(Vec<u8>, Option<u64>), CortexAdapterError>
pub fn snapshot(&self) -> Result<(Vec<u8>, Option<u64>), CortexAdapterError>
Capture a snapshot suitable for restore. Returns
(state_bytes, last_seq) — persist both together.
Sourcepub async fn open_from_snapshot(
redex: &Redex,
origin_hash: u64,
state_bytes: &[u8],
last_seq: Option<u64>,
) -> Result<Self, CortexAdapterError>
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.
Sourcepub 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>
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).