fix actor working

This commit is contained in:
2026-02-17 08:53:16 -06:00
parent fbdfbc1200
commit 2a38292ff7
8 changed files with 177 additions and 181 deletions

View File

@@ -706,14 +706,18 @@ $_.receiver = function receiver(fn) {
receive_fn = fn
}
// Holds all messages queued during the current turn.
var message_queue = []
$_.start = function start(cb, program) {
if (!program) return
var id = guid()
var oid = $_.self[ACTORDATA].id
var startup = {
id,
overling: $_.self,
root,
overling_id: oid,
root_id: root ? root[ACTORDATA].id : null,
program,
}
greeters[id] = cb
@@ -761,7 +765,7 @@ var couplings = {}
$_.couple = function couple(actor) {
if (actor == $_.self) return // can't couple to self
couplings[actor[ACTORDATA].id] = true
sys_msg(actor, {kind:'couple', from: $_.self})
sys_msg(actor, {kind:'couple', from_id: _cell.id})
log.system(`coupled to ${actor}`)
}
@@ -828,9 +832,6 @@ function actor_send(actor, message) {
log.system(`Unable to send message to actor ${actor[ACTORDATA]}`)
}
// Holds all messages queued during the current turn.
var message_queue = []
function send_messages() {
// if we've been flagged to stop, bail out before doing anything
if (need_stop) {
@@ -839,14 +840,17 @@ function send_messages() {
return
}
arrfor(message_queue, function(msg, index) {
if (msg.startup) {
// now is the time to actually spin up the actor
actor_mod.createactor(msg.startup)
var _qi = 0
var _qm = null
while (_qi < length(message_queue)) {
_qm = message_queue[_qi]
if (_qm.startup) {
actor_mod.createactor(_qm.startup)
} else {
actor_send(msg.actor, msg.send)
actor_send(_qm.actor, _qm.send)
}
})
_qi = _qi + 1
}
message_queue = []
}
@@ -892,7 +896,7 @@ function send(actor, message, reply) {
}
}, REPLYTIMEOUT)
send_msg.reply = id
send_msg.replycc = $_.self
send_msg.replycc_id = _cell.id
}
// Instead of sending immediately, queue it
@@ -923,29 +927,30 @@ if (config.actor_memory)
if (config.stack_max)
js.max_stacksize(config.system.stack_max);
overling = _cell.args.overling
overling = _cell.args.overling_id ? create_actor({id: _cell.args.overling_id}) : null
$_.overling = overling
root = _cell.args.root
root = _cell.args.root_id ? create_actor({id: _cell.args.root_id}) : null
if (root == null) root = $_.self
if (overling) {
$_.couple(overling) // auto couple to overling
report_to_overling({type:'greet', actor: $_.self})
$_.couple(overling)
report_to_overling({type:'greet', actor_id: _cell.id})
}
// sys messages are always dispatched immediately
function sys_msg(actor, msg)
{
actor_send(actor, {[SYSYM]:msg})
var envelope = {}
envelope[SYSYM] = msg
actor_send(actor, envelope)
}
// 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, from: $_.self})
sys_msg(overling, {kind:'underling', message:msg, from_id: _cell.id})
}
// Determine the program to run from command line
@@ -968,18 +973,26 @@ function handle_actor_disconnect(id) {
function handle_sysym(msg)
{
var from = null
var from_id = null
var from_actor = null
var greeter = null
var letter2 = null
var greet_msg = null
if (msg.kind == 'stop') {
actor_die("got stop message")
} else if (msg.kind == 'underling') {
from = msg.from
greeter = greeters[from[ACTORDATA].id]
if (greeter) greeter(msg.message)
from_id = msg.from_id
greeter = greeters[from_id]
if (greeter) {
greet_msg = msg.message
if (greet_msg.actor_id) {
greet_msg.actor = create_actor({id: greet_msg.actor_id})
}
greeter(greet_msg)
}
if (msg.message.type == 'disrupt')
delete underlings[from[ACTORDATA].id]
delete underlings[from_id]
} else if (msg.kind == 'contact') {
if (portal_fn) {
letter2 = msg.data
@@ -991,10 +1004,9 @@ function handle_sysym(msg)
disrupt
}
} else if (msg.kind == 'couple') {
// from must be notified when we die
from = msg.from
underlings[from[ACTORDATA].id] = true
log.system(`actor ${from} is coupled to me`)
from_id = msg.from_id
underlings[from_id] = true
log.system(`actor ${from_id} is coupled to me`)
}
}
@@ -1009,6 +1021,9 @@ function handle_message(msg) {
if (msg.type == "user") {
letter = msg.data // what the sender really sent
if (msg.replycc_id) {
msg.replycc = create_actor({id: msg.replycc_id})
}
letter[HEADER] = msg
letter[ACTORDATA] = { reply: msg.reply }