pub struct FnRunner {
pub trace_log: TraceLog,
/* private fields */
}Expand description
Manages the TypeScript process and executes function calls.
Fields§
§trace_log: TraceLogImplementations§
Source§impl FnRunner
impl FnRunner
Sourcepub fn new(trace_capacity: usize) -> Self
pub fn new(trace_capacity: usize) -> Self
Create a new runner with the given trace log capacity.
Sourcepub fn set_call_timeout(&self, timeout: Duration)
pub fn set_call_timeout(&self, timeout: Duration)
Override the per-call timeout. The default is 30s.
Sourcepub fn set_schedule_hook(&self, hook: ScheduleHook)
pub fn set_schedule_hook(&self, hook: ScheduleHook)
Install a callback to handle ctx.scheduler requests from functions.
Sourcepub fn set_nested_call_hook(&self, hook: NestedCallHook)
pub fn set_nested_call_hook(&self, hook: NestedCallHook)
Install a callback used for nested function calls (action → query or mutation). The callback is responsible for transactional wrapping when the nested fn is a mutation. Without this hook, nested mutations share the outer action’s non-transactional store and writes aren’t atomic.
Sourcepub fn start(&self, command: &str, args: &[&str]) -> Result<Vec<FnDef>, String>
pub fn start(&self, command: &str, args: &[&str]) -> Result<Vec<FnDef>, String>
Start the TypeScript process and complete the startup handshake.
Spawns the child + reader thread, waits for the runtime’s Ready
message, and only then publishes stdin/inbox/process so callers can
see the runner. This avoids the race where a concurrent call()
would consume the Ready message and desync the protocol.
On any failure (spawn, missing pipes, bad handshake, runtime-reported
error) the child is killed before returning so a half-alive process
doesn’t survive — important for the supervisor, which uses
is_alive() and would otherwise see “still running” forever.
Returns the function definitions reported by the runtime.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if the TypeScript process is running.
Sourcepub fn is_alive(&self) -> bool
pub fn is_alive(&self) -> bool
Returns true if the child process is alive. Distinct from is_running
which only checks that we ever started one — supervisor uses this.
Sourcepub fn respawn(&self) -> Result<Vec<FnDef>, String>
pub fn respawn(&self) -> Result<Vec<FnDef>, String>
Restart the underlying process using the command/args from the original
start() call. The supervisor uses this; callers should not need it.
Returns the freshly-handshaked function definitions. On any failure
the new child has already been killed by start().
Sourcepub fn kill(&self)
pub fn kill(&self)
Forcefully kill the child process. Used by the supervisor on timeout or when the runtime is shutting down. The reader thread will exit cleanly when its stdout closes.
Sourcepub fn handshake(&self) -> Result<Vec<FnDef>, String>
pub fn handshake(&self) -> Result<Vec<FnDef>, String>
Backwards-compatible: start() now performs the handshake itself
and returns the function definitions. handshake() is a no-op shim
that returns whatever the runtime is currently registered to.
Kept so existing callers (try_spawn_functions) compile without churn.
Sourcepub fn call(
&self,
store: &dyn DataStore,
fn_name: &str,
fn_type: FnType,
args: Value,
auth: AuthInfo,
on_stream: Option<StreamCallback>,
request: Option<RequestInfo>,
) -> Result<(Value, FnTrace), FnCallError>
pub fn call( &self, store: &dyn DataStore, fn_name: &str, fn_type: FnType, args: Value, auth: AuthInfo, on_stream: Option<StreamCallback>, request: Option<RequestInfo>, ) -> Result<(Value, FnTrace), FnCallError>
Execute a function call against the TypeScript process.
For mutations: the caller must hold the write lock and pass a transaction-capable store. For queries: uses the read pool, no locking required. For actions: no direct DB access, calls run_fn for nested queries/mutations.
Returns (return_value, trace). Stream chunks are delivered via the callback.
Sourcepub fn call_inner(
&self,
store: &dyn DataStore,
fn_name: &str,
fn_type: FnType,
args: Value,
auth: AuthInfo,
on_stream: Option<StreamCallback>,
request: Option<RequestInfo>,
) -> Result<(Value, FnTrace), FnCallError>
pub fn call_inner( &self, store: &dyn DataStore, fn_name: &str, fn_type: FnType, args: Value, auth: AuthInfo, on_stream: Option<StreamCallback>, request: Option<RequestInfo>, ) -> Result<(Value, FnTrace), FnCallError>
Protocol-only call — assumes the caller already holds io_lock.
This is the body of a call() minus the lock. It is pub so the
nested-call hook in FnOpsImpl can re-enter the protocol for a
transactional mutation wrap without re-acquiring the mutex (which
would deadlock since std::sync::Mutex is not re-entrant).
§Safety contract
Do not call directly from code that didn’t acquire io_lock via a
prior call() invocation. Callers outside this crate should use
call(); the only external caller is the nested-call hook.