@superhero/eventflow-hub 4.0.3 → 4.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -24,7 +24,11 @@ export function locate(locator)
24
24
  export default class Hub
25
25
  {
26
26
  #hubID
27
- channel = new Channel()
27
+
28
+ abortion = new AbortController()
29
+ channel = new Channel()
30
+ spokes = new SpokesManager()
31
+ subscribers = new SubscribersManager()
28
32
 
29
33
  get hubID()
30
34
  {
@@ -45,11 +49,8 @@ export default class Hub
45
49
  this.#hubID = (new IdNameGenerator().generateId() + '.' + config.NAME).toUpperCase()
46
50
  this.config = config
47
51
  this.db = db
48
- this.abortion = new AbortController()
49
52
  this.log = new Log({ label: `[${config.NAME}]` })
50
53
  this.certificates = new CertificatesManager(config.NAME, this.#hubID, config.certificates, db, this.log)
51
- this.spokes = new SpokesManager()
52
- this.subscribers = new SubscribersManager()
53
54
 
54
55
  this.channel.on('record', this.#onRecord.bind(this))
55
56
  }
@@ -63,11 +64,20 @@ export default class Hub
63
64
 
64
65
  async destroy()
65
66
  {
66
- this.abortion.abort()
67
+ const reason = new Error('hub is destroyed')
68
+ reason.code = 'E_EVENTFLOW_HUB_DESTROYED'
69
+
70
+ this.abortion.abort(reason)
67
71
  this.server?.close()
72
+
73
+ for(const socket of this.spokes.all)
74
+ {
75
+ socket.end()
76
+ }
77
+
68
78
  this.spokes.destroy()
69
79
  this.subscribers.destroy()
70
- this.log.warn`hub has quit`
80
+ this.log.warn`destroyed`
71
81
  await this.db.updateHubToQuit(this.#hubID)
72
82
  setTimeout(() => this.db.close(), 500)
73
83
  }
@@ -269,7 +279,7 @@ export default class Hub
269
279
 
270
280
  async #attemptToConsumeAndBroadcastPublishedMessage(domain, id, name, pid)
271
281
  {
272
- const consumed = await this.db.updateEventPublishedToConsumedByHub(domain, id, this.#hubID)
282
+ const consumed = await this.db.updateEventPublishedToConsumedByHub(id, this.#hubID)
273
283
 
274
284
  if(consumed)
275
285
  {
package/manager/spokes.js CHANGED
@@ -8,10 +8,7 @@ export default class SpokesManager
8
8
 
9
9
  destroy()
10
10
  {
11
- for(const socket of this.#set.values())
12
- {
13
- socket.end()
14
- }
11
+ this.#set.clear()
15
12
  }
16
13
 
17
14
  add(socket)
@@ -34,15 +34,14 @@ suite('@superhero/eventflow-hub/manager/spokes', () =>
34
34
  test('Destroy all sockets', async () =>
35
35
  {
36
36
  const manager = new SpokesManager()
37
- const socket1 = { id: 'socket1', end: () => socket1.destroyed = true }
38
- const socket2 = { id: 'socket2', end: () => socket2.destroyed = true }
37
+ const socket1 = { id: 'socket1' }
38
+ const socket2 = { id: 'socket2' }
39
39
 
40
40
  manager.add(socket1)
41
41
  manager.add(socket2)
42
42
  manager.destroy()
43
43
 
44
- assert.strictEqual(socket1.destroyed, true)
45
- assert.strictEqual(socket2.destroyed, true)
44
+ assert.strictEqual(manager.all.length, 0)
46
45
  })
47
46
 
48
47
  test('Handle deleting non-existent socket gracefully', async () =>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superhero/eventflow-hub",
3
- "version": "4.0.3",
3
+ "version": "4.0.4",
4
4
  "description": "Eventflow hub is the central server component in the eventflow ecosystem.",
5
5
  "keywords": [
6
6
  "eventflow",