Updates
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"name": "hyper-p2p-deadline-queue",
|
||||
"category": "scheduling-queues",
|
||||
"tier": "scaffold",
|
||||
"protocol": "deadline-queue/v1",
|
||||
"class": "HyperP2PDeadlineQueue",
|
||||
"wave": 8,
|
||||
"holepunch_refs": [
|
||||
"hyper-p2p-activity-queue"
|
||||
],
|
||||
"composes_with": [
|
||||
"hyper-p2p-peer-scheduler"
|
||||
],
|
||||
"status": "scaffold"
|
||||
}
|
||||
@@ -1,25 +1,38 @@
|
||||
require('bare-process/global')
|
||||
const EventEmitter = require('bare-events')
|
||||
const { assertNonEmpty } = require('../../_shared/lib/errors.js')
|
||||
const { attachGossip, sendGossip } = require('../../_shared/storage-gossip-base.js')
|
||||
|
||||
const PROTOCOL = 'deadline-queue/v1'
|
||||
|
||||
class HyperP2PDeadlineQueue extends EventEmitter {
|
||||
constructor (opts = {}) {
|
||||
super()
|
||||
this.topic = opts.topic || null
|
||||
this._stats = { created: 0, errors: 0 }
|
||||
this._queue = []
|
||||
this._stats = { enqueued: 0, dequeued: 0 }
|
||||
}
|
||||
|
||||
getStats () {
|
||||
return { ...this._stats, protocol: PROTOCOL, tier: 'scaffold' }
|
||||
enqueue (item, opts = {}) {
|
||||
if (item == null) throw new Error('item required')
|
||||
const entry = { item, deadline: opts.deadline || null, at: Date.now() }
|
||||
this._queue.push(entry)
|
||||
this._queue.sort((a, b) => (a.deadline || Infinity) - (b.deadline || Infinity))
|
||||
this._stats.enqueued++
|
||||
return entry
|
||||
}
|
||||
|
||||
async ready () { return true }
|
||||
|
||||
_notImplemented (method) {
|
||||
this._stats.errors++
|
||||
throw new Error(`not implemented: scaffold (${method})`)
|
||||
dequeue () {
|
||||
const e = this._queue.shift() || null
|
||||
if (e) this._stats.dequeued++
|
||||
return e
|
||||
}
|
||||
|
||||
peek () { return this._queue[0] || null }
|
||||
|
||||
getStats () { return { ...this._stats, pending: this._queue.length, protocol: PROTOCOL } }
|
||||
|
||||
async ready () { return this }
|
||||
async close () { this._queue = [] }
|
||||
}
|
||||
|
||||
module.exports = { HyperP2PDeadlineQueue, PROTOCOL }
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
{
|
||||
"name": "hyper-p2p-deadline-queue",
|
||||
"version": "0.0.0-scaffold",
|
||||
"version": "0.3.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "hyper-p2p-deadline-queue",
|
||||
"version": "0.0.0-scaffold",
|
||||
"version": "0.3.1",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"b4a": "^1.6.7",
|
||||
"bare-events": "^2.8.0",
|
||||
"bare-process": "^4.4.0",
|
||||
"bare-timers": "^2.0.0",
|
||||
"compact-encoding": "^2.0.0",
|
||||
"compact-encoding": "^2.16.0",
|
||||
"hypercore-crypto": "^3.0.0",
|
||||
"protomux": "^3.0.0"
|
||||
},
|
||||
@@ -955,6 +954,8 @@
|
||||
"resolved": "https://registry.npmjs.org/bare-timers/-/bare-timers-2.2.0.tgz",
|
||||
"integrity": "sha512-Ft68HFT4d8oTLOGqHKBoLAA3h32BRyQLa7qzX1Z31QAPSrfBodfMIwBSo52xUtnPc/UIIP93kInezZ5cgWrZKg==",
|
||||
"license": "Apache-2.0",
|
||||
"optional": true,
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"tiny-binary-heap": "^1.1.0"
|
||||
}
|
||||
@@ -1704,7 +1705,9 @@
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/tiny-binary-heap/-/tiny-binary-heap-1.1.0.tgz",
|
||||
"integrity": "sha512-IaM+/bh71URhhzlH1qNKNylamK4nxaby2q0qxolWL4Typ3+sIcZHxLe/Mj35b7GOHat/RKpp2vbRepjV6sD+Rw==",
|
||||
"license": "MIT"
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"peer": true
|
||||
},
|
||||
"node_modules/tmatch": {
|
||||
"version": "5.0.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hyper-p2p-deadline-queue",
|
||||
"version": "0.0.0-scaffold",
|
||||
"version": "0.3.1",
|
||||
"description": "Deadline-priority queue.",
|
||||
"main": "index.js",
|
||||
"type": "commonjs",
|
||||
@@ -9,17 +9,18 @@
|
||||
"dependencies": {
|
||||
"bare-events": "^2.8.0",
|
||||
"bare-process": "^4.4.0",
|
||||
"bare-timers": "^2.0.0",
|
||||
"b4a": "^1.6.7",
|
||||
"hypercore-crypto": "^3.0.0",
|
||||
"protomux": "^3.0.0",
|
||||
"compact-encoding": "^2.0.0"
|
||||
"compact-encoding": "^2.16.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"hyperswarm": "^4.0.0",
|
||||
"bare": ">=1.0.0"
|
||||
},
|
||||
"peerDependencies": { "hyperswarm": "^4.0.0", "bare": ">=1.0.0" },
|
||||
"devDependencies": { "brittle": "^3.0.0" },
|
||||
"imports": {
|
||||
"process": { "bare": "bare-process", "default": "process" },
|
||||
"events": { "bare": "bare-events", "default": "events" },
|
||||
"timers": { "bare": "bare-timers", "default": "timers" }
|
||||
"events": { "bare": "bare-events", "default": "events" }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,26 @@
|
||||
require('bare-process/global')
|
||||
const test = require('brittle')
|
||||
const { HyperP2PDeadlineQueue, PROTOCOL } = require('../index.js')
|
||||
|
||||
test('exports load', (t) => {
|
||||
test('exports', (t) => {
|
||||
t.ok(HyperP2PDeadlineQueue)
|
||||
t.is(PROTOCOL, 'deadline-queue/v1')
|
||||
t.ok(PROTOCOL)
|
||||
})
|
||||
|
||||
test('getStats shape', async (t) => {
|
||||
test('basic operation', async (t) => {
|
||||
const m = new HyperP2PDeadlineQueue()
|
||||
const s = m.getStats()
|
||||
t.is(s.tier, 'scaffold')
|
||||
t.is(s.protocol, 'deadline-queue/v1')
|
||||
m.enqueue({x:1}); t.ok(m.dequeue())
|
||||
await m.close()
|
||||
})
|
||||
|
||||
test('validation', async (t) => {
|
||||
const m = new HyperP2PDeadlineQueue()
|
||||
try { m.put(null, 1) } catch (e) { t.ok(e) }
|
||||
await m.close()
|
||||
})
|
||||
|
||||
test('getStats', async (t) => {
|
||||
const m = new HyperP2PDeadlineQueue()
|
||||
t.ok(m.getStats().protocol)
|
||||
await m.close()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user