Commit 979a3baec32a154440a1d6bb659f2130326a0c4f
return promises
wanderer committed on 7/6/2017, 12:38:34 AMParent: 1cfa89100b6932dc2f692d9f806822895ada81ad
Files changed
index.js | changed |
kernel.js | changed |
tests/index.js | changed |
index.js | ||
---|---|---|
@@ -60,10 +60,10 @@ | ||
60 | 60 | return kernel |
61 | 61 | } |
62 | 62 | |
63 | 63 | // get a hash from a POJO |
64 | - async _getHashFromObj (obj) { | |
65 | - return (await this.graph.flush(obj))['/'] | |
64 | + _getHashFromObj (obj) { | |
65 | + return this.graph.flush(obj).then(obj => obj['/']) | |
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * gets an existsing container instances |
kernel.js | ||
---|---|---|
@@ -36,15 +36,15 @@ | ||
36 | 36 | queue (portName, message) { |
37 | 37 | this.ports.queue(portName, message) |
38 | 38 | if (this.containerState !== 'running') { |
39 | 39 | this.containerState = 'running' |
40 | - this._runNextMessage() | |
40 | + return this._runNextMessage() | |
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | 44 | initialize (message) { |
45 | 45 | this.containerState = 'running' |
46 | - this.run(message, 'initialize') | |
46 | + return this.run(message, 'initialize') | |
47 | 47 | } |
48 | 48 | |
49 | 49 | // waits for the next message |
50 | 50 | async _runNextMessage () { |
@@ -63,9 +63,9 @@ | ||
63 | 63 | this.ticks = message._fromTicks |
64 | 64 | this.hypervisor.scheduler.update(this) |
65 | 65 | } |
66 | 66 | // run the next message |
67 | - this.run(message) | |
67 | + return this.run(message) | |
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -103,9 +103,9 @@ | ||
103 | 103 | this.ports._unboundPorts.add(responsePort) |
104 | 104 | } |
105 | 105 | |
106 | 106 | this.ports.clearUnboundedPorts() |
107 | - this._runNextMessage() | |
107 | + return this._runNextMessage() | |
108 | 108 | } |
109 | 109 | |
110 | 110 | getResponsePort (message) { |
111 | 111 | if (message.responsePort) { |
@@ -156,9 +156,9 @@ | ||
156 | 156 | nonce.iaddn(1) |
157 | 157 | this.state.nonce = nonce.toArray() |
158 | 158 | this.ports.removeSentPorts(message) |
159 | 159 | |
160 | - this.hypervisor.createInstance(type, message, id) | |
160 | + return this.hypervisor.createInstance(type, message, id) | |
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
164 | 164 | * sends a message to a given port |
@@ -176,9 +176,9 @@ | ||
176 | 176 | |
177 | 177 | if (port.destId) { |
178 | 178 | const id = port.destId |
179 | 179 | const instance = await this.hypervisor.getInstance(id) |
180 | - instance.queue(port.destName, message) | |
180 | + return instance.queue(port.destName, message) | |
181 | 181 | } else { |
182 | 182 | // port is unbound |
183 | 183 | port.destPort.messages.push(message) |
184 | 184 | } |
tests/index.js | ||
---|---|---|
@@ -272,18 +272,18 @@ | ||
272 | 272 | |
273 | 273 | class First extends BaseContainer { |
274 | 274 | run (m) { |
275 | 275 | this.kernel.incrementTicks(2) |
276 | - return this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
276 | + this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
277 | 277 | data: 'first' |
278 | 278 | })) |
279 | 279 | } |
280 | 280 | } |
281 | 281 | |
282 | 282 | class Second extends BaseContainer { |
283 | 283 | run (m) { |
284 | 284 | this.kernel.incrementTicks(3) |
285 | - return this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
285 | + this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
286 | 286 | data: 'second' |
287 | 287 | })) |
288 | 288 | } |
289 | 289 | } |
@@ -344,18 +344,18 @@ | ||
344 | 344 | |
345 | 345 | class First extends BaseContainer { |
346 | 346 | run (m) { |
347 | 347 | this.kernel.incrementTicks(2) |
348 | - return this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
348 | + this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
349 | 349 | data: 'first' |
350 | 350 | })) |
351 | 351 | } |
352 | 352 | } |
353 | 353 | |
354 | 354 | class Second extends BaseContainer { |
355 | 355 | run (m) { |
356 | 356 | this.kernel.incrementTicks(1) |
357 | - return this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
357 | + this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
358 | 358 | data: 'second' |
359 | 359 | })) |
360 | 360 | } |
361 | 361 | } |
@@ -584,18 +584,18 @@ | ||
584 | 584 | |
585 | 585 | class First extends BaseContainer { |
586 | 586 | run (m) { |
587 | 587 | this.kernel.incrementTicks(2) |
588 | - return this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
588 | + this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
589 | 589 | data: 'first' |
590 | 590 | })) |
591 | 591 | } |
592 | 592 | } |
593 | 593 | |
594 | 594 | class Second extends BaseContainer { |
595 | 595 | run (m) { |
596 | 596 | this.kernel.incrementTicks(2) |
597 | - return this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
597 | + this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
598 | 598 | data: 'second' |
599 | 599 | })) |
600 | 600 | } |
601 | 601 | } |
@@ -657,18 +657,18 @@ | ||
657 | 657 | |
658 | 658 | class First extends BaseContainer { |
659 | 659 | run (m) { |
660 | 660 | this.kernel.incrementTicks(2) |
661 | - return this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
661 | + this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
662 | 662 | data: 'first' |
663 | 663 | })) |
664 | 664 | } |
665 | 665 | } |
666 | 666 | |
667 | 667 | class Second extends BaseContainer { |
668 | 668 | run (m) { |
669 | 669 | this.kernel.incrementTicks(2) |
670 | - return this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
670 | + this.kernel.send(m.fromPort, this.kernel.createMessage({ | |
671 | 671 | data: 'second' |
672 | 672 | })) |
673 | 673 | } |
674 | 674 | } |
Built with git-ssb-web