fix actor not dying if killed while not in a turn
This commit is contained in:
@@ -535,7 +535,7 @@ var couplings = new Set()
|
||||
$_.couple = function couple(actor) {
|
||||
if (actor === $_) return // can't couple to self
|
||||
couplings.add(actor[ACTORDATA].id)
|
||||
sys_msg(actor, {kind:'couple'})
|
||||
sys_msg(actor, {kind:'couple', from: $_})
|
||||
log.system(`coupled to ${actor}`)
|
||||
}
|
||||
$_.couple[cell.DOC] = "causes this actor to stop when another actor stops."
|
||||
@@ -685,14 +685,14 @@ if (overling) {
|
||||
// sys messages are always dispatched immediately
|
||||
function sys_msg(actor, msg)
|
||||
{
|
||||
actor_send(actor, {[SYSYM]:msg, from:$_})
|
||||
actor_send(actor, {[SYSYM]:msg})
|
||||
}
|
||||
|
||||
// messages sent to here get put into the cb provided to start
|
||||
function report_to_overling(msg)
|
||||
{
|
||||
if (!overling) return
|
||||
sys_msg(overling, {kind:'underling', message:msg})
|
||||
sys_msg(overling, {kind:'underling', message:msg, from: $_})
|
||||
}
|
||||
|
||||
if (!cell.args.program)
|
||||
@@ -708,13 +708,15 @@ function handle_actor_disconnect(id) {
|
||||
if (couplings.has(id)) disrupt("coupled actor died") // couplings now disrupts instead of stop
|
||||
}
|
||||
|
||||
function handle_sysym(msg, from)
|
||||
function handle_sysym(msg)
|
||||
{
|
||||
|
||||
switch(msg.kind) {
|
||||
case 'stop':
|
||||
disrupt("got stop message")
|
||||
break
|
||||
case 'underling':
|
||||
var from = msg.from
|
||||
var greeter = greeters[from[ACTORDATA].id]
|
||||
if (greeter) greeter(msg.message)
|
||||
if (msg.message.type == 'disrupt')
|
||||
@@ -729,6 +731,7 @@ function handle_sysym(msg, from)
|
||||
} else throw new Error('Got a contact message, but no portal is established.')
|
||||
break
|
||||
case 'couple': // from must be notified when we die
|
||||
var from = msg.from
|
||||
underlings.add(from[ACTORDATA].id)
|
||||
log.system(`actor ${from} is coupled to me`)
|
||||
break
|
||||
|
||||
@@ -633,6 +633,9 @@ void tracy_end_hook(JSContext *js, JSValue fn)
|
||||
void actor_disrupt(cell_rt *crt)
|
||||
{
|
||||
crt->disrupt = 1;
|
||||
|
||||
if (crt->state != ACTOR_RUNNING)
|
||||
actor_free(crt);
|
||||
}
|
||||
|
||||
static int actor_interrupt_cb(JSRuntime *rt, cell_rt *crt)
|
||||
|
||||
@@ -12,4 +12,4 @@ $_.start(e => {
|
||||
log.console(`underling successfully killed.`)
|
||||
$_.stop()
|
||||
}
|
||||
}, 'hang')
|
||||
}, 'hang')
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
$_.start(e => {
|
||||
log.console("SENDING!")
|
||||
send(e.actor, { message: "Hello! Good to go?" }, msg => {
|
||||
log.console(`Original sender got message back: ${json.encode(msg)}. Stopping!`)
|
||||
$_.stop()
|
||||
|
||||
Reference in New Issue
Block a user