Skip to content

Core\Script\Handle

A script that spawn script started. The only thing you can do with it is await it, which waits until that script ends.

Core\Script\Handle is the value spawn script 'file.nvs' answers: the name of a child script already running in its own isolated memory. It has no members. The only thing to do with one is await it, which waits for the child and answers its result — ok, output, value and error — and a second await on the same handle throws LogicError, because the first one collected the child. A child's own failure arrives as ok being false, never as a throw in the parent. Spawning needs the script.spawn capability from nvs.toml; the construct, its with(...) options and the result's fields are in concurrency.

[[app]]
entry = "main.nvs"
[app.capabilities.script]
spawn = true
<?nvs
echo 'child says hello';
return 6 * 7;
<?nvs
var $job = spawn script 'child.nvs' with(output: 'capture');
echo 'spawned', "\n";
var $done = await $job;
echo 'ok=', $done->ok ? 'true' : 'false', "\n";
echo 'output=', $done->output, "\n";
echo 'value=', $done->value as int, "\n";
try {
var $again = await $job;
} catch (LogicError $twice) {
echo 'a handle is awaited once', "\n";
}
Output
spawned
ok=true
output=child says hello
value=42
a handle is awaited once