Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

sys::net - Netidx Operations

The sys::net module provides publish/subscribe and RPC operations via netidx.

type Table = { rows: Array<string>, columns: Array<string> };
type RpcArg<'a> = { default: 'a, doc: string };

/// Write the value to the specified path. When its arm wakes, the write
/// attaches to the path again and writes only when the value or the path
/// fires.
val write: fn<'a: Data>(path: string, value: 'a) -> Result<_, `WriteError(string)>;

/// subscribe to the specified path
val subscribe: fn<'a: Concrete>(path: string) -> Result<'a, [`SubscribeError(string), `InvalidCast(string)]>;

/// call the specified rpc. args must be a struct or null.
val call: fn<'a: Data, 'b: Concrete>(path: string, args: 'a) -> Result<'b, [`RpcError(string), `InvalidCast(string)]>;

/// Publish an rpc,
/// - spec ('spec) must be a struct where every field is a RpcArg, or null (no arguments)
/// - the argument to f ('args) must be a struct with the same fields as 'spec,
///   or null if 'spec is null
/// - every field in 'args must contain the type of the corresponding default in 'spec
/// Each call runs an instance of f of its own and is answered by its first
/// value, or by the error it raises. A call runs to its answer whether or not
/// the caller is still waiting; one f never answers holds the call.
val rpc: fn<'spec: Data, 'result: Data, 'args: Concrete + Data>(
    #path:string,
    #doc:string,
    #spec:'spec,
    #f:fn(args: 'args) -> 'result throws 'e
) -> Result<_, `PublishRpcError(string)> throws 'e;

/// list paths under the specified path.
val list: fn(?#update:Any, path: string) -> Result<Array<string>, `ListError(string)>;

/// list the table under the specified path.
val list_table: fn(?#update:Any, path: string) -> Result<Table, `ListError(string)>;

/// Publish the specifed value at the specified path. A write to it is cast
/// to #on_write's argument type, and a value that does not cast answers the
/// writer with the cast's error. Without a handler the publication takes no
/// writes, and while the handler is null a write answers the writer with an
/// error.
val publish: fn<'v: Data, 'a: Concrete + Data>(?#on_write:[fn(v: 'a) -> _ throws 'e, null], path: string, v: 'v) -> Result<_, `PublishError(string)> throws 'e;