diff --git a/scripts/engine.cm b/scripts/engine.cm index e0e04f9e..15d6f91d 100644 --- a/scripts/engine.cm +++ b/scripts/engine.cm @@ -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 diff --git a/source/cell.c b/source/cell.c index e7869992..9db8e0c9 100644 --- a/source/cell.c +++ b/source/cell.c @@ -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) diff --git a/tests/kill.ce b/tests/kill.ce index d18456c8..08826228 100644 --- a/tests/kill.ce +++ b/tests/kill.ce @@ -12,4 +12,4 @@ $_.start(e => { log.console(`underling successfully killed.`) $_.stop() } -}, 'hang') \ No newline at end of file +}, 'hang') diff --git a/tests/send.ce b/tests/send.ce index 2f5931e6..8770c45c 100644 --- a/tests/send.ce +++ b/tests/send.ce @@ -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()