Skip to main content

Module turn

Module turn 

Source
Expand description

A plugin in Rust on both targets (docs/PLUGINS.md §8.3): in process natively, a WASM reactor on wasm32-wasip1, with the same source.

A reactor keeps its state between two calls of its export escouade-turn, as an instance of run.js does. The host writes on its standard input, which never blocks, then calls a turn: the plugin reads what came and writes its lines, and the turn ends. Nothing waits inside a turn: an answer of the host comes as a line of a later turn.

  • run is what a state machine calls in place of crate::serve; escouade-plugin-kit has its own, for a plugin whose calls wait.
  • crate::module! exports the turn. It is one line of the plugin, nothing at all natively.
  • instance_id and read_file are what std::process::id and std::fs cannot be in a module.
  • On wasm32, lines, write, flush, set_turn are the kit’s way in, and host_call the synchronous door to the host (escouade.call).

Functions§

instance_id
What tells the ids of this instance from those of the one before it, restarted: its process.
read_file
A file a state machine must have before it answers: from the disk natively; in a module, read by the host, under a folder the plugin declares (fs/read, docs/PLUGINS.md §8.4.6). None when it cannot be read, or is refused.
run
The loop of a state machine, whatever the target: natively, crate::serve on the standard input and output until they end, its exit code answered; in a module, handler kept for the turns to come.