@toa.io/core 0.2.1-dev.3 → 0.3.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/core",
3
- "version": "0.2.1-dev.3",
3
+ "version": "0.3.0",
4
4
  "description": "Toa Core",
5
5
  "author": "temich <tema.gurtovoy@gmail.com>",
6
6
  "homepage": "https://github.com/toa-io/toa#readme",
package/src/component.js CHANGED
@@ -21,11 +21,11 @@ class Component extends Connector {
21
21
  Object.values(operations).forEach((operation) => this.depends(operation))
22
22
  }
23
23
 
24
- async connection () {
24
+ async open () {
25
25
  console.info(`Runtime '${this.locator.id}' connected`)
26
26
  }
27
27
 
28
- disconnected () {
28
+ async dispose () {
29
29
  console.info(`Runtime '${this.locator.id}' disconnected`)
30
30
  }
31
31
 
@@ -13,11 +13,11 @@ class Composition extends Connector {
13
13
  if (tenants.length > 0) this.depends(tenants)
14
14
  }
15
15
 
16
- async connection () {
16
+ async open () {
17
17
  console.info('Composition complete')
18
18
  }
19
19
 
20
- async disconnected () {
20
+ async dispose () {
21
21
  console.info('Composition shutdown complete')
22
22
  }
23
23
  }
package/src/connector.js CHANGED
@@ -3,7 +3,6 @@
3
3
  const { console } = require('@toa.io/console')
4
4
  const { newid } = require('@toa.io/generic')
5
5
 
6
- // noinspection JSClosureCompilerSyntax
7
6
  /**
8
7
  * Abstract connections hierarchy
9
8
  * @implements {toa.core.Connector}
@@ -11,10 +10,13 @@ const { newid } = require('@toa.io/generic')
11
10
  class Connector {
12
11
  /** @type {Array<Connector>} */
13
12
  #dependencies = []
13
+
14
14
  /** @type {Array<Connector>} */
15
15
  #links = []
16
+
16
17
  /** @type {Promise} */
17
18
  #connecting
19
+
18
20
  /** @type {Promise} */
19
21
  #disconnecting
20
22
 
@@ -88,7 +90,7 @@ class Connector {
88
90
 
89
91
  this.#connecting = (async () => {
90
92
  await Promise.all(this.#dependencies.map((connector) => connector.connect()))
91
- await this.connection()
93
+ await this.open()
92
94
  })()
93
95
 
94
96
  try {
@@ -133,13 +135,13 @@ class Connector {
133
135
  if (delay > DELAY) console.warn(`Connector ${this.id} still disconnecting (${delay})`)
134
136
  }, DELAY)
135
137
 
136
- if (interrupt !== true) await this.disconnection()
138
+ if (interrupt !== true) await this.close()
137
139
 
138
140
  clearInterval(interval)
139
141
 
140
142
  await Promise.all(this.#dependencies.map(connector => connector.disconnect()))
141
143
 
142
- this.disconnected()
144
+ await this.dispose()
143
145
  })()
144
146
 
145
147
  await this.#disconnecting
@@ -162,24 +164,18 @@ class Connector {
162
164
 
163
165
  /**
164
166
  * Called on connection
165
- *
166
- * @returns {Promise<void>}
167
167
  */
168
- async connection () {}
168
+ async open () {}
169
169
 
170
170
  /**
171
171
  * Called on disconnection
172
- *
173
- * @returns {Promise<void>}
174
172
  */
175
- async disconnection () {}
173
+ async close () {}
176
174
 
177
175
  /**
178
176
  * Called after self and dependants disconnection is complete
179
- *
180
- * @returns {void}
181
177
  */
182
- disconnected () {}
178
+ async dispose () {}
183
179
  }
184
180
 
185
181
  const DELAY = 5000
package/src/discovery.js CHANGED
@@ -13,7 +13,7 @@ class Discovery extends Connector {
13
13
  this.#lookup = lookup
14
14
  }
15
15
 
16
- async connection () {
16
+ async open () {
17
17
  this.#lookups = {}
18
18
  }
19
19
 
package/src/reflection.js CHANGED
@@ -20,7 +20,7 @@ class Reflection extends Connector {
20
20
  this.#source = source
21
21
  }
22
22
 
23
- async connection () {
23
+ async open () {
24
24
  this.value = await this.#source()
25
25
  }
26
26
  }
package/src/remote.js CHANGED
@@ -5,11 +5,11 @@ const { console } = require('@toa.io/console')
5
5
  const { Component } = require('./component')
6
6
 
7
7
  class Remote extends Component {
8
- async connection () {
8
+ async open () {
9
9
  console.info(`Remote '${this.locator.id}' connected`)
10
10
  }
11
11
 
12
- async disconnected () {
12
+ async dispose () {
13
13
  console.info(`Remote '${this.locator.id}' disconnected`)
14
14
  }
15
15
  }
@@ -14,23 +14,23 @@ class TestConnector extends Connector {
14
14
  this.#label = label
15
15
  }
16
16
 
17
- async connection () {
17
+ async open () {
18
18
  await timeout(random(10))
19
19
  this.#seq.push(`+${this.#label}`)
20
20
  }
21
21
 
22
- async disconnection () {
22
+ async close () {
23
23
  await timeout(random(10))
24
24
  this.#seq.push(`-${this.#label}`)
25
25
  }
26
26
 
27
- disconnected () {
27
+ async dispose () {
28
28
  this.#seq.push(`*${this.#label}`)
29
29
  }
30
30
  }
31
31
 
32
32
  class FailingConnector extends Connector {
33
- async connection () {
33
+ async open () {
34
34
  await timeout(random(10))
35
35
  throw new Error('FailingConnector')
36
36
  }
@@ -16,7 +16,7 @@ beforeEach(async () => {
16
16
  emission = new Emission(fixtures.events)
17
17
  event = clone(fixtures.event)
18
18
 
19
- await emission.connection()
19
+ await emission.open()
20
20
  })
21
21
 
22
22
  it('should depend on events', () => {
@@ -14,8 +14,8 @@ declare namespace toa.core.bindings {
14
14
  emit(message: _core.Message): Promise<void>
15
15
  }
16
16
 
17
- interface Broadcaster extends _core.Connector {
18
- send(label: string, payload: Object): Promise<void>
17
+ interface Broadcast extends _core.Connector {
18
+ transmit(label: string, payload: object): Promise<void>
19
19
 
20
20
  receive(label: string, callback: (payload: object) => Promise<void>): Promise<void>
21
21
  }
@@ -27,9 +27,9 @@ declare namespace toa.core.bindings {
27
27
 
28
28
  emitter?(locator: _core.Locator, label: string): Emitter
29
29
 
30
- receiver?(locator: _core.Locator, label: string, id: string, receiver: _core.Receiver): _core.Connector
30
+ receiver?(locator: _core.Locator, label: string, group: string, receiver: _core.Receiver): _core.Connector
31
31
 
32
- broadcaster?(name: string, group?: string): Broadcaster
32
+ broadcast?(name: string, group?: string): Broadcast
33
33
  }
34
34
 
35
35
  }
@@ -12,9 +12,11 @@ declare namespace toa.core {
12
12
 
13
13
  disconnect(interrupt?: boolean): Promise<void>
14
14
 
15
- connection(): Promise<void>
15
+ open(): Promise<void>
16
16
 
17
- disconnection(): Promise<void>
17
+ close(): Promise<void>
18
+
19
+ dispose(): Promise<void>
18
20
  }
19
21
 
20
22
  }