closes #19: kill underlings with system level interrupts

This commit is contained in:
2025-06-06 12:20:49 -05:00
parent 6687008d1a
commit e0595de71a
6 changed files with 57 additions and 22 deletions

View File

@@ -512,8 +512,8 @@ $_.stop = function stop(actor) {
throw new Error('Can only call stop on an actor.')
if (!underlings.has(actor[ACTORDATA].id))
throw new Error('Can only call stop on an underling or self.')
sys_msg(actor, {kind:"stop"})
sys_msg(actor, "stop")
}
$_.stop[cell.DOC] = "The stop function stops an underling."
@@ -712,14 +712,13 @@ function handle_sysym(msg, from)
{
switch(msg.kind) {
case 'stop':
if (from[ACTORDATA].id !== overling[ACTORDATA].id)
log.error(`Got a message from a random actor ${msg.id} to stop`)
else
disrupt("got stop message")
disrupt("got stop message")
break
case 'underling':
var greeter = greeters[from[ACTORDATA].id]
if (greeter) greeter(msg.message)
if (msg.message.type == 'disrupt')
underlings.delete(from[ACTORDATA].id)
break
case 'contact':
if (portal_fn) {
@@ -810,10 +809,14 @@ var progContent = io.slurp(prog)
var prog_script = `(function ${cell.args.program.name()}_start($_, arg) { var args = arg; ${progContent} })`
var val = js.eval(cell.args.program, prog_script)($_, cell.args.arg)
if (val)
throw new Error('Program must not return anything');
// queue up its first turn instead of run immediately
send_messages()
var startfn = js.eval(cell.args.program, prog_script);
$_.delay(_ => {
var val = startfn($_, cell.args.arg);
if (val)
throw new Error('Program must not return anything');
}, 0)
})()