Expand economy, autobase, network, observability, and scheduling modules.
Add auction withdraw/cancel, marketplace search helpers, update gossip history, autobase fork/lease/indexer/view APIs, link-probe and circuit-loom utilities, trace trees, pheromone ranking, and scheduling/measurement helpers with tests. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -55,6 +55,21 @@ class HyperP2PPeerScheduler extends EventEmitter {
|
||||
return ok
|
||||
}
|
||||
|
||||
nextDue (jobId) {
|
||||
const job = this._jobs.get(jobId)
|
||||
return job ? job.nextAt : null
|
||||
}
|
||||
|
||||
dueJobs (now = Date.now()) {
|
||||
return [...this._jobs.values()].filter((j) => now >= j.nextAt)
|
||||
}
|
||||
|
||||
msUntil (jobId, now = Date.now()) {
|
||||
const job = this._jobs.get(jobId)
|
||||
if (!job) return null
|
||||
return Math.max(0, job.nextAt - now)
|
||||
}
|
||||
|
||||
_isLeader (shard) {
|
||||
if (!this.topicLease) return true
|
||||
const holder = this.topicLease.holder(shard)
|
||||
|
||||
@@ -13,6 +13,16 @@ test('peer-scheduler: schedule and manual tick', async (t) => {
|
||||
await s.close()
|
||||
})
|
||||
|
||||
test('peer-scheduler: nextDue dueJobs msUntil', async (t) => {
|
||||
const s = new HyperP2PPeerScheduler()
|
||||
const id = s.schedule(500, 'j')
|
||||
const due = s.nextDue(id)
|
||||
t.ok(due > Date.now())
|
||||
t.is(s.dueJobs(due - 1).length, 0)
|
||||
t.ok(s.msUntil(id) <= 500)
|
||||
await s.close()
|
||||
})
|
||||
|
||||
test('peer-scheduler: no background timer by default', async (t) => {
|
||||
const s = new HyperP2PPeerScheduler()
|
||||
t.is(s.enableBackgroundTimers, false)
|
||||
|
||||
Reference in New Issue
Block a user