git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 979a3baec32a154440a1d6bb659f2130326a0c4f

return promises

wanderer committed on 7/6/2017, 12:38:34 AM
Parent: 1cfa89100b6932dc2f692d9f806822895ada81ad

Files changed

index.jschanged
kernel.jschanged
tests/index.jschanged
index.jsView
@@ -60,10 +60,10 @@
6060 return kernel
6161 }
6262
6363 // 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['/'])
6666 }
6767
6868 /**
6969 * gets an existsing container instances
kernel.jsView
@@ -36,15 +36,15 @@
3636 queue (portName, message) {
3737 this.ports.queue(portName, message)
3838 if (this.containerState !== 'running') {
3939 this.containerState = 'running'
40- this._runNextMessage()
40+ return this._runNextMessage()
4141 }
4242 }
4343
4444 initialize (message) {
4545 this.containerState = 'running'
46- this.run(message, 'initialize')
46+ return this.run(message, 'initialize')
4747 }
4848
4949 // waits for the next message
5050 async _runNextMessage () {
@@ -63,9 +63,9 @@
6363 this.ticks = message._fromTicks
6464 this.hypervisor.scheduler.update(this)
6565 }
6666 // run the next message
67- this.run(message)
67+ return this.run(message)
6868 }
6969 }
7070
7171 /**
@@ -103,9 +103,9 @@
103103 this.ports._unboundPorts.add(responsePort)
104104 }
105105
106106 this.ports.clearUnboundedPorts()
107- this._runNextMessage()
107+ return this._runNextMessage()
108108 }
109109
110110 getResponsePort (message) {
111111 if (message.responsePort) {
@@ -156,9 +156,9 @@
156156 nonce.iaddn(1)
157157 this.state.nonce = nonce.toArray()
158158 this.ports.removeSentPorts(message)
159159
160- this.hypervisor.createInstance(type, message, id)
160+ return this.hypervisor.createInstance(type, message, id)
161161 }
162162
163163 /**
164164 * sends a message to a given port
@@ -176,9 +176,9 @@
176176
177177 if (port.destId) {
178178 const id = port.destId
179179 const instance = await this.hypervisor.getInstance(id)
180- instance.queue(port.destName, message)
180+ return instance.queue(port.destName, message)
181181 } else {
182182 // port is unbound
183183 port.destPort.messages.push(message)
184184 }
tests/index.jsView
@@ -272,18 +272,18 @@
272272
273273 class First extends BaseContainer {
274274 run (m) {
275275 this.kernel.incrementTicks(2)
276- return this.kernel.send(m.fromPort, this.kernel.createMessage({
276+ this.kernel.send(m.fromPort, this.kernel.createMessage({
277277 data: 'first'
278278 }))
279279 }
280280 }
281281
282282 class Second extends BaseContainer {
283283 run (m) {
284284 this.kernel.incrementTicks(3)
285- return this.kernel.send(m.fromPort, this.kernel.createMessage({
285+ this.kernel.send(m.fromPort, this.kernel.createMessage({
286286 data: 'second'
287287 }))
288288 }
289289 }
@@ -344,18 +344,18 @@
344344
345345 class First extends BaseContainer {
346346 run (m) {
347347 this.kernel.incrementTicks(2)
348- return this.kernel.send(m.fromPort, this.kernel.createMessage({
348+ this.kernel.send(m.fromPort, this.kernel.createMessage({
349349 data: 'first'
350350 }))
351351 }
352352 }
353353
354354 class Second extends BaseContainer {
355355 run (m) {
356356 this.kernel.incrementTicks(1)
357- return this.kernel.send(m.fromPort, this.kernel.createMessage({
357+ this.kernel.send(m.fromPort, this.kernel.createMessage({
358358 data: 'second'
359359 }))
360360 }
361361 }
@@ -584,18 +584,18 @@
584584
585585 class First extends BaseContainer {
586586 run (m) {
587587 this.kernel.incrementTicks(2)
588- return this.kernel.send(m.fromPort, this.kernel.createMessage({
588+ this.kernel.send(m.fromPort, this.kernel.createMessage({
589589 data: 'first'
590590 }))
591591 }
592592 }
593593
594594 class Second extends BaseContainer {
595595 run (m) {
596596 this.kernel.incrementTicks(2)
597- return this.kernel.send(m.fromPort, this.kernel.createMessage({
597+ this.kernel.send(m.fromPort, this.kernel.createMessage({
598598 data: 'second'
599599 }))
600600 }
601601 }
@@ -657,18 +657,18 @@
657657
658658 class First extends BaseContainer {
659659 run (m) {
660660 this.kernel.incrementTicks(2)
661- return this.kernel.send(m.fromPort, this.kernel.createMessage({
661+ this.kernel.send(m.fromPort, this.kernel.createMessage({
662662 data: 'first'
663663 }))
664664 }
665665 }
666666
667667 class Second extends BaseContainer {
668668 run (m) {
669669 this.kernel.incrementTicks(2)
670- return this.kernel.send(m.fromPort, this.kernel.createMessage({
670+ this.kernel.send(m.fromPort, this.kernel.createMessage({
671671 data: 'second'
672672 }))
673673 }
674674 }

Built with git-ssb-web