.nib std
nib 0.3.0

module use "std/system.nib"

System

System.Remote, an instance whose operations are answered by another process over a socket. A wire binds it to an interface of yours, and that interface becomes the protocol.

System.Remote is an effector that lives in another process. It has no operations of its own: a wire binds it to an interface, and it answers that interface's operations by sending each one to a daemon over a Unix socket (unix:/path) or TCP (tcp:host:port). The program does not change. @Sql.Db.query(…) is the same call whether a nib effector or a SQLite daemon answers it, and the wire decides which.

use "std/system.nib"

data NoKey where
  NoKey(String)

interface Kv where
  put(k: String, v: String) -> ();
  get(k: String) -> String raises NoKey

module App where
  func main :: -> String ! Kv raises NoKey =
    let _ = @Kv.put("greeting", "hello");
    @Kv.get("greeting")

wire Prod runs App.main where Kv = System.Remote{ at: "unix:/run/nib/kv.sock" }

That block is checked, not run: nothing listens on that socket here. Binding Kv to an ordinary nib effector instead is a one-line change to the wire, and so is wrapping the remote instance in one of your own: Kv = System.Remote{ at: "unix:…" } |> Cached builds Cached around it, exactly as for any instance.

What may cross

Every value an interface bound to System.Remote moves crosses a process boundary as JSON, so it must be data: Int, Float, String, Bool, Json, Bytes, (), a Vec, Set or Map of data, a record, or a data type built from those. A function, an interface, a handle or a type parameter cannot, and the checker refuses the binding by naming the operation and the reason. The address is checked too: a System.Remote with no at field is refused at the wire.

An answer is decoded against the type the interface declares, so a program receives its own records and sums, not a Json it has to take apart. A daemon's raise must be one of the operation's declared tags, and a rescue catches it like any other raise.

When the daemon is not there

A transport failure is not a raise the program can catch: no daemon, a closed socket, or an answer that does not decode ends the run with a runtime error naming the address and the operation. A program that should survive its database going away says so in its interface, and the daemon raises that.

The daemon, and the journal

At its first operation the instance sends the interface and a 16-hex digest of its declaration, so a daemon written against another declaration refuses to serve it. system/tools/nib-remote in the nib tree is a Rust crate for writing daemons, and nib-sqlite is the first one.

In a recorded run (--journal-out), every remote answer is written to the journal, and a replay (--journal-in) serves those answers without connecting: a replay needs no daemon, and never touches the database behind one.

Functions

func remote_protocol :: -> Int

The version of the wire protocol this nibc speaks to a daemon: the protocol field of its first frame.

System.remote_protocol()
1