Skip to main content

FnRunner

Struct FnRunner 

Source
pub struct FnRunner {
    pub trace_log: TraceLog,
    /* private fields */
}
Expand description

Manages the TypeScript process and executes function calls.

Fields§

§trace_log: TraceLog

Implementations§

Source§

impl FnRunner

Source

pub fn new(trace_capacity: usize) -> Self

Create a new runner with the given trace log capacity.

Source

pub fn set_call_timeout(&self, timeout: Duration)

Override the per-call timeout. The default is 30s.

Source

pub fn set_schedule_hook(&self, hook: ScheduleHook)

Install a callback to handle ctx.scheduler requests from functions.

Source

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.

Source

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.

Source

pub fn is_running(&self) -> bool

Check if the TypeScript process is running.

Source

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.

Source

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().

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Drop for FnRunner

Source§

fn drop(&mut self)

Executes the destructor for this type. 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, 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