@toa.io/core 0.2.1-dev.2 → 0.2.1-dev.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/package.json +1 -1
- package/src/component.js +2 -2
- package/src/composition.js +2 -2
- package/src/connector.js +9 -13
- package/src/discovery.js +1 -1
- package/src/reflection.js +1 -1
- package/src/remote.js +2 -2
- package/test/connector.fixtures.js +4 -4
- package/test/emission.test.js +1 -1
- package/types/bindings.d.ts +4 -4
- package/types/connector.d.ts +4 -2
package/package.json
CHANGED
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
|
|
24
|
+
async open () {
|
|
25
25
|
console.info(`Runtime '${this.locator.id}' connected`)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
async dispose () {
|
|
29
29
|
console.info(`Runtime '${this.locator.id}' disconnected`)
|
|
30
30
|
}
|
|
31
31
|
|
package/src/composition.js
CHANGED
|
@@ -13,11 +13,11 @@ class Composition extends Connector {
|
|
|
13
13
|
if (tenants.length > 0) this.depends(tenants)
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
async
|
|
16
|
+
async open () {
|
|
17
17
|
console.info('Composition complete')
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
async
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
168
|
+
async open () {}
|
|
169
169
|
|
|
170
170
|
/**
|
|
171
171
|
* Called on disconnection
|
|
172
|
-
*
|
|
173
|
-
* @returns {Promise<void>}
|
|
174
172
|
*/
|
|
175
|
-
async
|
|
173
|
+
async close () {}
|
|
176
174
|
|
|
177
175
|
/**
|
|
178
176
|
* Called after self and dependants disconnection is complete
|
|
179
|
-
*
|
|
180
|
-
* @returns {void}
|
|
181
177
|
*/
|
|
182
|
-
|
|
178
|
+
async dispose () {}
|
|
183
179
|
}
|
|
184
180
|
|
|
185
181
|
const DELAY = 5000
|
package/src/discovery.js
CHANGED
package/src/reflection.js
CHANGED
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
|
|
8
|
+
async open () {
|
|
9
9
|
console.info(`Remote '${this.locator.id}' connected`)
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
async
|
|
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
|
|
17
|
+
async open () {
|
|
18
18
|
await timeout(random(10))
|
|
19
19
|
this.#seq.push(`+${this.#label}`)
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
async
|
|
22
|
+
async close () {
|
|
23
23
|
await timeout(random(10))
|
|
24
24
|
this.#seq.push(`-${this.#label}`)
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
async dispose () {
|
|
28
28
|
this.#seq.push(`*${this.#label}`)
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
class FailingConnector extends Connector {
|
|
33
|
-
async
|
|
33
|
+
async open () {
|
|
34
34
|
await timeout(random(10))
|
|
35
35
|
throw new Error('FailingConnector')
|
|
36
36
|
}
|
package/test/emission.test.js
CHANGED
package/types/bindings.d.ts
CHANGED
|
@@ -14,8 +14,8 @@ declare namespace toa.core.bindings {
|
|
|
14
14
|
emit(message: _core.Message): Promise<void>
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
interface
|
|
18
|
-
|
|
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,
|
|
30
|
+
receiver?(locator: _core.Locator, label: string, group: string, receiver: _core.Receiver): _core.Connector
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
broadcast?(name: string, group?: string): Broadcast
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
}
|
package/types/connector.d.ts
CHANGED