add actor clock, random, unneeded
Some checks failed
Build and Deploy / build-linux (push) Failing after 1m45s
Build and Deploy / build-windows (CLANG64) (push) Failing after 9m53s
Build and Deploy / package-dist (push) Has been skipped
Build and Deploy / deploy-itch (push) Has been skipped
Build and Deploy / deploy-gitea (push) Has been skipped

This commit is contained in:
2025-03-05 22:34:08 -06:00
parent a8865594ca
commit e71a823848
3 changed files with 25 additions and 10 deletions

View File

@@ -521,9 +521,17 @@ js.eval(DOCPATH, script)()
var enet = use('enet')
var util = use('util')
var math = use('math')
var $_ = {}
$_.random = math.rand
$_.clock = function(fn)
{
return os.now()
}
var underlings = new Set()
var overling = undefined
@@ -599,9 +607,14 @@ $_.stop = function(actor)
})
}
$_.unneeded = function(fn, seconds)
{
var unneeded_fn = $_.stop
var unneeded_time = ar
$_.unneeded = function(fn, seconds = ar)
{
if (typeof fn !== 'function') throw new Error ('Must supply a function to unneeded.')
unneeded_fn = fn
unneeded_time = seconds
}
$_.delay = function(fn, seconds)
@@ -611,7 +624,6 @@ $_.delay = function(fn, seconds)
}
var guid2actor = new Map()
var couplings = new Set()
$_.couple = function(actor)
@@ -621,8 +633,9 @@ $_.couple = function(actor)
use('cmd')(prosperon.argv)
if (prosperon.overling)
$_.host.connect("localhost", args.overling)
if (prosperon.overling) {
$_.host.connect("localhost", prosperon.args.overling)
}
if (prosperon.program)
actor.spawn(prosperon.program)
@@ -671,7 +684,7 @@ var hang = 0.016
while (1) {
os.waitevent(e => {
unneeded_timer()
unneded_timer = $_.delay($_.stop, ar)
unneeded_timer = $_.delay(unneeded_fn, unneeded_time)
}, hang)
host.service(e => {
unneeded_timer()
@@ -692,7 +705,7 @@ while (1) {
handle_actor_disconnect(guid2actor.get(e.peer))
break
}
unneeded_timer = $_.delay($_.stop, ar)
unneeded_timer = $_.delay(unneeded_fn, unneeded_time)
}, hang);
}

View File

@@ -150,12 +150,12 @@ Cmdline.register_order(
"spawn",
function(argv) {
prosperon.args = parse_args(argv)
if (!args.program)
if (!prosperon.args.program)
os.exit()
prosperon.guid = prosperon.args.guid
prosperon.overling = prosperon.args.overling
prosperon.program = args.program
prosperon.program = prosperon.args.program
},
"Spawn a new prosperon actor.",
"TOPIC"

View File

@@ -8,10 +8,12 @@ $_.start(e => {
console.log(`sending stop message to ${json.encode(e.data)}`)
$_.stop(e.data)
}, 1);
$_.couple(e.data)
// $_.couple(e.data)
}
}, "tests/underling.js");
$_.unneeded(_ => {console.log("I haven't got a message in a while")}, 3)
$_.contact((actor, reason) => {
}, {
address: "localhost",