Commit b17f430cb428dc0322dc3915948f9c7802107eda
fix ports
wanderer committed on 8/8/2017, 11:18:14 PMParent: 4d0111a3323bd33403464ccb1760f2df9aaa623e
Files changed
tests/index.js | changed |
tests/index.js | ||
---|---|---|
@@ -13,9 +13,9 @@ | ||
13 | 13 … | onCreation (message) { |
14 | 14 … | this.kernel.state.code = message.data.byteLength ? message.data : undefined |
15 | 15 … | const port = message.ports[0] |
16 | 16 … | if (port) { |
17 | - this.kernel.ports.bind('root', port) | |
17 … | + return this.kernel.ports.bind('root', port) | |
18 | 18 … | } |
19 | 19 … | } |
20 | 20 … | static get typeId () { |
21 | 21 … | return 9 |
@@ -26,9 +26,9 @@ | ||
26 | 26 … | tape('basic', async t => { |
27 | 27 … | t.plan(3) |
28 | 28 … | let message |
29 | 29 … | const expectedState = { |
30 | - '/': 'zdpuAsvLUNKxnxpKxuipCJz7sH4kmHuu3gVEUEmJ1QuWnikht' | |
30 … | + '/': 'zdpuApGUFnjcY3eBeVPFfnEgGunPz8vyXVJbrkgBmYwrbVDpA' | |
31 | 31 … | } |
32 | 32 … | |
33 | 33 … | class testVMContainer extends BaseContainer { |
34 | 34 … | onMessage (m) { |
@@ -49,17 +49,15 @@ | ||
49 | 49 … | }) |
50 | 50 … | |
51 | 51 … | rootContainer.createInstance(testVMContainer.typeId, initMessage) |
52 | 52 … | |
53 | - rootContainer.ports.bind('first', portRef1) | |
53 … | + await rootContainer.ports.bind('first', portRef1) | |
54 | 54 … | message = rootContainer.createMessage() |
55 | 55 … | rootContainer.send(portRef1, message) |
56 | 56 … | |
57 | 57 … | const stateRoot = await hypervisor.createStateRoot(Infinity) |
58 | 58 … | t.deepEquals(stateRoot, expectedState, 'expected root!') |
59 | 59 … | t.equals(hypervisor.scheduler.oldest(), 0) |
60 | - await hypervisor.graph.tree(stateRoot, Infinity, true) | |
61 | - console.log(JSON.stringify(stateRoot, null, 2)) | |
62 | 60 … | } catch (e) { |
63 | 61 … | console.log(e) |
64 | 62 … | } |
65 | 63 … | }) |
@@ -80,9 +78,9 @@ | ||
80 | 78 … | |
81 | 79 … | const root = await hypervisor.createInstance(testVMContainer.typeId) |
82 | 80 … | const [portRef1, portRef2] = root.ports.createChannel() |
83 | 81 … | |
84 | - root.ports.bind('one', portRef1) | |
82 … | + await root.ports.bind('one', portRef1) | |
85 | 83 … | root.createInstance(testVMContainer.typeId, root.createMessage({ |
86 | 84 … | ports: [portRef2] |
87 | 85 … | })) |
88 | 86 … | |
@@ -99,9 +97,9 @@ | ||
99 | 97 … | tape('one child contract with saturated ports', async t => { |
100 | 98 … | t.plan(2) |
101 | 99 … | let message |
102 | 100 … | const expectedState = { |
103 | - '/': 'zdpuAnfZ1fGUSzNwAovfArzcTfEVbXjVYABprgtjUKMtGb8k5' | |
101 … | + '/': 'zdpuArCqpDZtEqjrXrRhMiYLE7QQ1szVr1qLVkiwtDLincGWU' | |
104 | 102 … | } |
105 | 103 … | |
106 | 104 … | class testVMContainer2 extends BaseContainer { |
107 | 105 … | onMessage (m) { |
@@ -117,11 +115,11 @@ | ||
117 | 115 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
118 | 116 … | this.kernel.createInstance(testVMContainer2.typeId, this.kernel.createMessage({ |
119 | 117 … | ports: [portRef2] |
120 | 118 … | })) |
121 | - this.kernel.ports.bind('child', portRef1) | |
122 | 119 … | this.kernel.incrementTicks(2) |
123 | 120 … | this.kernel.send(portRef1, m) |
121 … | + return this.kernel.ports.bind('child', portRef1) | |
124 | 122 … | } |
125 | 123 … | } |
126 | 124 … | |
127 | 125 … | const hypervisor = new Hypervisor(node.dag) |
@@ -133,19 +131,19 @@ | ||
133 | 131 … | root.createInstance(testVMContainer.typeId, root.createMessage({ |
134 | 132 … | ports: [portRef2] |
135 | 133 … | })) |
136 | 134 … | |
137 | - root.ports.bind('first', portRef1) | |
135 … | + await root.ports.bind('first', portRef1) | |
138 | 136 … | message = root.createMessage({ |
139 | 137 … | data: 'test' |
140 | 138 … | }) |
141 | 139 … | |
142 | 140 … | root.send(portRef1, message) |
143 | 141 … | const stateRoot = await hypervisor.createStateRoot(Infinity) |
144 | 142 … | |
143 … | + t.deepEquals(stateRoot, expectedState, 'expected state') | |
145 | 144 … | // await hypervisor.graph.tree(stateRoot, Infinity, true) |
146 | 145 … | // console.log(JSON.stringify(stateRoot, null, 2)) |
147 | - t.deepEquals(stateRoot, expectedState, 'expected state') | |
148 | 146 … | }) |
149 | 147 … | |
150 | 148 … | tape('one child contract', async t => { |
151 | 149 … | t.plan(4) |
@@ -177,11 +175,11 @@ | ||
177 | 175 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
178 | 176 … | this.kernel.createInstance(testVMContainer2.typeId, this.kernel.createMessage({ |
179 | 177 … | ports: [portRef2] |
180 | 178 … | })) |
181 | - this.kernel.ports.bind('child', portRef1) | |
182 | 179 … | this.kernel.send(portRef1, m) |
183 | 180 … | this.kernel.incrementTicks(1) |
181 … | + return this.kernel.ports.bind('child', portRef1) | |
184 | 182 … | } |
185 | 183 … | } |
186 | 184 … | |
187 | 185 … | const hypervisor = new Hypervisor(node.dag) |
@@ -194,9 +192,9 @@ | ||
194 | 192 … | root.createInstance(testVMContainer.typeId, root.createMessage({ |
195 | 193 … | ports: [portRef2] |
196 | 194 … | })) |
197 | 195 … | |
198 | - root.ports.bind('first', portRef1) | |
196 … | + await root.ports.bind('first', portRef1) | |
199 | 197 … | message = root.createMessage() |
200 | 198 … | |
201 | 199 … | root.send(portRef1, message) |
202 | 200 … | const stateRoot = await hypervisor.createStateRoot(Infinity) |
@@ -228,11 +226,13 @@ | ||
228 | 226 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
229 | 227 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
230 | 228 … | const [portRef5, portRef6] = this.kernel.ports.createChannel() |
231 | 229 … | |
232 | - this.kernel.ports.bind('one', portRef1) | |
233 | - this.kernel.ports.bind('two', portRef3) | |
234 | - this.kernel.ports.bind('three', portRef5) | |
230 … | + await Promise.all( | |
231 … | + this.kernel.ports.bind('one', portRef1), | |
232 … | + this.kernel.ports.bind('two', portRef3), | |
233 … | + this.kernel.ports.bind('three', portRef5) | |
234 … | + ) | |
235 | 235 … | |
236 | 236 … | const message1 = this.kernel.createMessage({ |
237 | 237 … | ports: [portRef2] |
238 | 238 … | }) |
@@ -258,9 +258,9 @@ | ||
258 | 258 … | await root.message(root.createMessage()) |
259 | 259 … | const stateRoot = await hypervisor.createStateRoot() |
260 | 260 … | |
261 | 261 … | t.deepEquals(stateRoot, { |
262 | - '/': 'zdpuAtChoDT1Er7c9Ndv6ov4m46wibCNY1HKthoVLUn5n4Rg5' | |
262 … | + '/': 'zdpuAoifKuJkWz9Fjvt79NmGq3tcefhfCyq8iM8YhcFdV9bmZ' | |
263 | 263 … | }, 'should revert the state') |
264 | 264 … | }) |
265 | 265 … | |
266 | 266 … | tape('message should arrive in the correct oder if sent in order', async t => { |
@@ -274,11 +274,8 @@ | ||
274 | 274 … | |
275 | 275 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
276 | 276 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
277 | 277 … | |
278 | - this.kernel.ports.bind('two', portRef3) | |
279 | - this.kernel.ports.bind('one', portRef1) | |
280 | - | |
281 | 278 … | const message1 = this.kernel.createMessage({ |
282 | 279 … | ports: [portRef2] |
283 | 280 … | }) |
284 | 281 … | const message2 = this.kernel.createMessage({ |
@@ -289,8 +286,12 @@ | ||
289 | 286 … | this.kernel.createInstance(Second.typeId, message2) |
290 | 287 … | |
291 | 288 … | this.kernel.send(portRef1, this.kernel.createMessage()) |
292 | 289 … | this.kernel.send(portRef3, this.kernel.createMessage()) |
290 … | + return Promise.all( | |
291 … | + this.kernel.ports.bind('two', portRef3), | |
292 … | + this.kernel.ports.bind('one', portRef1) | |
293 … | + ) | |
293 | 294 … | } else if (runs === 1) { |
294 | 295 … | runs++ |
295 | 296 … | t.equals(m.data, 'first', 'should recive the first message') |
296 | 297 … | } else if (runs === 2) { |
@@ -337,9 +338,9 @@ | ||
337 | 338 … | root.createInstance(Root.typeId, root.createMessage({ |
338 | 339 … | ports: [portRef2] |
339 | 340 … | })) |
340 | 341 … | |
341 | - root.ports.bind('first', portRef1) | |
342 … | + await root.ports.bind('first', portRef1) | |
342 | 343 … | const message = root.createMessage() |
343 | 344 … | root.send(portRef1, message) |
344 | 345 … | }) |
345 | 346 … | |
@@ -354,11 +355,8 @@ | ||
354 | 355 … | |
355 | 356 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
356 | 357 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
357 | 358 … | |
358 | - this.kernel.ports.bind('one', portRef1) | |
359 | - this.kernel.ports.bind('two', portRef3) | |
360 | - | |
361 | 359 … | const message1 = this.kernel.createMessage({ |
362 | 360 … | ports: [portRef2] |
363 | 361 … | }) |
364 | 362 … | const message2 = this.kernel.createMessage({ |
@@ -369,8 +367,13 @@ | ||
369 | 367 … | this.kernel.createInstance(Second.typeId, message2) |
370 | 368 … | |
371 | 369 … | this.kernel.send(portRef1, this.kernel.createMessage()) |
372 | 370 … | this.kernel.send(portRef3, this.kernel.createMessage()) |
371 … | + | |
372 … | + return Promise.all([ | |
373 … | + this.kernel.ports.bind('one', portRef1), | |
374 … | + this.kernel.ports.bind('two', portRef3) | |
375 … | + ]) | |
373 | 376 … | } else if (runs === 1) { |
374 | 377 … | runs++ |
375 | 378 … | t.equals(m.data, 'second', 'should recived the second message') |
376 | 379 … | } else if (runs === 2) { |
@@ -417,9 +420,9 @@ | ||
417 | 420 … | root.createInstance(Root.typeId, root.createMessage({ |
418 | 421 … | ports: [portRef2] |
419 | 422 … | })) |
420 | 423 … | |
421 | - root.ports.bind('first', portRef1) | |
424 … | + await root.ports.bind('first', portRef1) | |
422 | 425 … | const message = root.createMessage() |
423 | 426 … | root.send(portRef1, message) |
424 | 427 … | }) |
425 | 428 … | |
@@ -433,10 +436,8 @@ | ||
433 | 436 … | runs++ |
434 | 437 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
435 | 438 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
436 | 439 … | |
437 | - this.kernel.ports.bind('one', portRef1) | |
438 | - this.kernel.ports.bind('two', portRef3) | |
439 | 440 … | |
440 | 441 … | const message1 = this.kernel.createMessage({ |
441 | 442 … | ports: [portRef2] |
442 | 443 … | }) |
@@ -450,8 +451,13 @@ | ||
450 | 451 … | this.kernel.send(portRef1, this.kernel.createMessage()) |
451 | 452 … | this.kernel.send(portRef3, this.kernel.createMessage()) |
452 | 453 … | |
453 | 454 … | this.kernel.incrementTicks(6) |
455 … | + | |
456 … | + return Promise.all([ | |
457 … | + this.kernel.ports.bind('one', portRef1), | |
458 … | + this.kernel.ports.bind('two', portRef3) | |
459 … | + ]) | |
454 | 460 … | } else if (runs === 1) { |
455 | 461 … | runs++ |
456 | 462 … | t.equals(m.data, 'first', 'should recive the first message') |
457 | 463 … | } else if (runs === 2) { |
@@ -495,9 +501,9 @@ | ||
495 | 501 … | root.createInstance(Root.typeId, root.createMessage({ |
496 | 502 … | ports: [portRef2] |
497 | 503 … | })) |
498 | 504 … | |
499 | - root.ports.bind('first', portRef1) | |
505 … | + await root.ports.bind('first', portRef1) | |
500 | 506 … | const message = root.createMessage() |
501 | 507 … | root.send(portRef1, message) |
502 | 508 … | }) |
503 | 509 … | |
@@ -511,11 +517,8 @@ | ||
511 | 517 … | runs++ |
512 | 518 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
513 | 519 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
514 | 520 … | |
515 | - this.kernel.ports.bind('one', portRef1) | |
516 | - this.kernel.ports.bind('two', portRef3) | |
517 | - | |
518 | 521 … | const message1 = this.kernel.createMessage({ |
519 | 522 … | ports: [portRef2] |
520 | 523 … | }) |
521 | 524 … | const message2 = this.kernel.createMessage({ |
@@ -528,8 +531,12 @@ | ||
528 | 531 … | this.kernel.send(portRef1, this.kernel.createMessage()) |
529 | 532 … | this.kernel.send(portRef3, this.kernel.createMessage()) |
530 | 533 … | |
531 | 534 … | this.kernel.incrementTicks(6) |
535 … | + return Promise.all([ | |
536 … | + this.kernel.ports.bind('one', portRef1), | |
537 … | + this.kernel.ports.bind('two', portRef3) | |
538 … | + ]) | |
532 | 539 … | } else if (runs === 1) { |
533 | 540 … | runs++ |
534 | 541 … | t.equals(m.data, 'first', 'should recive the first message') |
535 | 542 … | } else if (runs === 2) { |
@@ -587,15 +594,15 @@ | ||
587 | 594 … | const [portRef1, portRef2] = root.ports.createChannel() |
588 | 595 … | |
589 | 596 … | const message = root.createMessage() |
590 | 597 … | root.send(portRef1, message) |
591 | - root.ports.bind('first', portRef1) | |
598 … | + await root.ports.bind('first', portRef1) | |
592 | 599 … | root.createInstance(Root.typeId, root.createMessage({ |
593 | 600 … | ports: [portRef2] |
594 | 601 … | })) |
595 | 602 … | |
596 | 603 … | const [portRef3, portRef4] = root.ports.createChannel() |
597 | - root.ports.bind('sencond', portRef3) | |
604 … | + await root.ports.bind('sencond', portRef3) | |
598 | 605 … | root.createInstance(Waiter.typeId, root.createMessage({ |
599 | 606 … | ports: [portRef4] |
600 | 607 … | })) |
601 | 608 … | |
@@ -615,11 +622,8 @@ | ||
615 | 622 … | runs++ |
616 | 623 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
617 | 624 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
618 | 625 … | |
619 | - this.kernel.ports.bind('two', portRef3) | |
620 | - this.kernel.ports.bind('one', portRef1) | |
621 | - | |
622 | 626 … | const message1 = this.kernel.createMessage({ |
623 | 627 … | ports: [portRef2] |
624 | 628 … | }) |
625 | 629 … | const message2 = this.kernel.createMessage({ |
@@ -632,8 +636,12 @@ | ||
632 | 636 … | this.kernel.send(portRef1, this.kernel.createMessage()) |
633 | 637 … | this.kernel.send(portRef3, this.kernel.createMessage()) |
634 | 638 … | |
635 | 639 … | this.kernel.incrementTicks(6) |
640 … | + return Promise.all([ | |
641 … | + this.kernel.ports.bind('two', portRef3), | |
642 … | + this.kernel.ports.bind('one', portRef1) | |
643 … | + ]) | |
636 | 644 … | } else if (runs === 1) { |
637 | 645 … | runs++ |
638 | 646 … | t.equals(m.data, 'second', 'should recived the second message') |
639 | 647 … | } else if (runs === 2) { |
@@ -679,9 +687,9 @@ | ||
679 | 687 … | const [portRef1, portRef2] = root.ports.createChannel() |
680 | 688 … | const message = root.createMessage() |
681 | 689 … | |
682 | 690 … | root.send(portRef1, message) |
683 | - root.ports.bind('first', portRef1) | |
691 … | + await root.ports.bind('first', portRef1) | |
684 | 692 … | root.createInstance(Root.typeId, root.createMessage({ |
685 | 693 … | ports: [portRef2] |
686 | 694 … | })) |
687 | 695 … | }) |
@@ -691,16 +699,16 @@ | ||
691 | 699 … | |
692 | 700 … | let runs = 0 |
693 | 701 … | |
694 | 702 … | class Root extends BaseContainer { |
695 | - onMessage (m) { | |
703 … | + async onMessage (m) { | |
696 | 704 … | if (!runs) { |
697 | 705 … | runs++ |
698 | 706 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
699 | 707 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
700 | 708 … | |
701 | - this.kernel.ports.bind('one', portRef1) | |
702 | - this.kernel.ports.bind('two', portRef3) | |
709 … | + await this.kernel.ports.bind('one', portRef1) | |
710 … | + await this.kernel.ports.bind('two', portRef3) | |
703 | 711 … | |
704 | 712 … | const message1 = this.kernel.createMessage({ |
705 | 713 … | ports: [portRef2] |
706 | 714 … | }) |
@@ -758,9 +766,9 @@ | ||
758 | 766 … | const [portRef1, portRef2] = root.ports.createChannel() |
759 | 767 … | const message = root.createMessage() |
760 | 768 … | |
761 | 769 … | root.send(portRef1, message) |
762 | - root.ports.bind('first', portRef1) | |
770 … | + await root.ports.bind('first', portRef1) | |
763 | 771 … | root.createInstance(Root.typeId, root.createMessage({ |
764 | 772 … | ports: [portRef2] |
765 | 773 … | })) |
766 | 774 … | }) |
@@ -775,13 +783,13 @@ | ||
775 | 783 … | onMessage (m) { |
776 | 784 … | let one = this.kernel.ports.get('one') |
777 | 785 … | if (!one) { |
778 | 786 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
779 | - this.kernel.ports.bind('one', portRef1) | |
780 | 787 … | const message1 = this.kernel.createMessage({ |
781 | 788 … | ports: [portRef2] |
782 | 789 … | }) |
783 | 790 … | this.kernel.createInstance(First.typeId, message1) |
791 … | + return this.kernel.ports.bind('one', portRef1) | |
784 | 792 … | } else { |
785 | 793 … | this.kernel.send(one, this.kernel.createMessage()) |
786 | 794 … | this.kernel.send(one, this.kernel.createMessage()) |
787 | 795 … | } |
@@ -808,9 +816,9 @@ | ||
808 | 816 … | hypervisor.registerContainer(First) |
809 | 817 … | |
810 | 818 … | const root = await hypervisor.createInstance(Root.typeId) |
811 | 819 … | const [portRef1, portRef2] = root.ports.createChannel() |
812 | - root.ports.bind('first', portRef1) | |
820 … | + await root.ports.bind('first', portRef1) | |
813 | 821 … | root.createInstance(Root.typeId, root.createMessage({ |
814 | 822 … | ports: [portRef2] |
815 | 823 … | })) |
816 | 824 … | |
@@ -832,9 +840,9 @@ | ||
832 | 840 … | const [portRef1, portRef2] = root.ports.createChannel() |
833 | 841 … | root.createInstance(BaseContainer.typeId, root.createMessage({ |
834 | 842 … | ports: [portRef2] |
835 | 843 … | })) |
836 | - root.ports.bind('test', portRef1) | |
844 … | + await root.ports.bind('test', portRef1) | |
837 | 845 … | |
838 | 846 … | try { |
839 | 847 … | root.createMessage({ |
840 | 848 … | ports: [portRef1] |
@@ -869,16 +877,16 @@ | ||
869 | 877 … | } |
870 | 878 … | class Root extends BaseContainer { |
871 | 879 … | onMessage (m) { |
872 | 880 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
873 | - this.kernel.ports.bind('one', portRef1) | |
874 | 881 … | const message1 = this.kernel.createMessage({ |
875 | 882 … | ports: [portRef2] |
876 | 883 … | }) |
877 | 884 … | |
878 | 885 … | this.kernel.createInstance(First.typeId, message1) |
879 | 886 … | this.kernel.send(portRef1, this.kernel.createMessage()) |
880 | 887 … | this.kernel.incrementTicks(6) |
888 … | + return this.kernel.ports.bind('one', portRef1) | |
881 | 889 … | } |
882 | 890 … | } |
883 | 891 … | |
884 | 892 … | class First extends BaseContainer { |
@@ -897,9 +905,9 @@ | ||
897 | 905 … | hypervisor.registerContainer(First) |
898 | 906 … | |
899 | 907 … | const root = await hypervisor.createInstance(Root.typeId) |
900 | 908 … | const [portRef1, portRef2] = root.ports.createChannel() |
901 | - root.ports.bind('first', portRef1) | |
909 … | + await root.ports.bind('first', portRef1) | |
902 | 910 … | root.createInstance(Root.typeId, root.createMessage({ |
903 | 911 … | ports: [portRef2] |
904 | 912 … | })) |
905 | 913 … | |
@@ -914,9 +922,9 @@ | ||
914 | 922 … | }) |
915 | 923 … | |
916 | 924 … | tape('clear unbounded ports', async t => { |
917 | 925 … | const expectedSr = { |
918 | - '/': 'zdpuAxVzUQRWaAeFWXq5TgDpZqPaNgNp1ZuEfxbxg7h4qnXmC' | |
926 … | + '/': 'zdpuAopMy53q2uvL2a4fhVEAvwXjSDW28fh8zhQUj598tb5md' | |
919 | 927 … | } |
920 | 928 … | class Root extends BaseContainer { |
921 | 929 … | onMessage (m) { |
922 | 930 … | this.kernel.createInstance(Root.typeId) |
@@ -928,9 +936,9 @@ | ||
928 | 936 … | hypervisor.registerContainer(Root) |
929 | 937 … | |
930 | 938 … | const root = await hypervisor.createInstance(Root.typeId) |
931 | 939 … | const [portRef1, portRef2] = root.ports.createChannel() |
932 | - root.ports.bind('first', portRef1) | |
940 … | + await root.ports.bind('first', portRef1) | |
933 | 941 … | root.createInstance(Root.typeId, root.createMessage({ |
934 | 942 … | ports: [portRef2] |
935 | 943 … | })) |
936 | 944 … | |
@@ -955,13 +963,13 @@ | ||
955 | 963 … | } |
956 | 964 … | } |
957 | 965 … | |
958 | 966 … | class Sub extends BaseContainer { |
959 | - onInitailize (message) { | |
960 | - this.kernel.ports.bind('root', message.ports[0]) | |
961 | - const [portRef1, portRef2] = root.ports.createChannel() | |
962 | - root.ports.bind('child', portRef1) | |
963 | - root.createInstance(Root.typeId, root.createMessage({ | |
967 … | + async onInitailize (message) { | |
968 … | + await this.kernel.ports.bind('root', message.ports[0]) | |
969 … | + const [portRef1, portRef2] = this.kernel.ports.createChannel() | |
970 … | + await this.kernel.ports.bind('child', portRef1) | |
971 … | + this.kernel.createInstance(Root.typeId, this.kernel.createMessage({ | |
964 | 972 … | ports: [portRef2] |
965 | 973 … | })) |
966 | 974 … | } |
967 | 975 … | static get typeId () { |
@@ -975,9 +983,9 @@ | ||
975 | 983 … | hypervisor.registerContainer(Sub) |
976 | 984 … | |
977 | 985 … | const root = await hypervisor.createInstance(Root.typeId) |
978 | 986 … | const [portRef1, portRef2] = root.ports.createChannel() |
979 | - root.ports.bind('first', portRef1) | |
987 … | + await root.ports.bind('first', portRef1) | |
980 | 988 … | root.createInstance(Root.typeId, root.createMessage({ |
981 | 989 … | ports: [portRef2] |
982 | 990 … | })) |
983 | 991 … | |
@@ -992,25 +1000,25 @@ | ||
992 | 1000 … | const expectedSr = { |
993 | 1001 … | '/': 'zdpuApKrsvsWknDML2Mme9FyZfRnVZ1hTCoKzkooYAWT3dUDV' |
994 | 1002 … | } |
995 | 1003 … | class Root extends BaseContainer { |
996 | - onMessage (m) { | |
1004 … | + async onMessage (m) { | |
997 | 1005 … | if (m.ports.length) { |
998 | 1006 … | const port = this.kernel.ports.get('test1') |
999 | 1007 … | this.kernel.send(port, m) |
1000 | - this.kernel.ports.unbind('test1') | |
1008 … | + return this.kernel.ports.unbind('test1') | |
1001 | 1009 … | } else { |
1002 | 1010 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
1003 | 1011 … | this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
1004 | 1012 … | ports: [portRef2] |
1005 | 1013 … | })) |
1006 | - this.kernel.ports.bind('test1', portRef1) | |
1014 … | + await this.kernel.ports.bind('test1', portRef1) | |
1007 | 1015 … | |
1008 | 1016 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
1009 | 1017 … | this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
1010 | 1018 … | ports: [portRef4] |
1011 | 1019 … | })) |
1012 | - this.kernel.ports.bind('test2', portRef3) | |
1020 … | + await this.kernel.ports.bind('test2', portRef3) | |
1013 | 1021 … | this.kernel.send(portRef3, this.kernel.createMessage({ |
1014 | 1022 … | data: 'getChannel' |
1015 | 1023 … | })) |
1016 | 1024 … | } |
@@ -1020,15 +1028,15 @@ | ||
1020 | 1028 … | class Sub extends BaseContainer { |
1021 | 1029 … | onMessage (message) { |
1022 | 1030 … | if (message.data === 'getChannel') { |
1023 | 1031 … | const ports = this.kernel.ports.createChannel() |
1024 | - this.kernel.ports.bind('channel', ports[0]) | |
1025 | 1032 … | this.kernel.send(message.fromPort, this.kernel.createMessage({ |
1026 | 1033 … | data: 'bindPort', |
1027 | 1034 … | ports: [ports[1]] |
1028 | 1035 … | })) |
1036 … | + return this.kernel.ports.bind('channel', ports[0]) | |
1029 | 1037 … | } else if (message.data === 'bindPort') { |
1030 | - this.kernel.ports.bind('channel', message.ports[0]) | |
1038 … | + return this.kernel.ports.bind('channel', message.ports[0]) | |
1031 | 1039 … | } |
1032 | 1040 … | } |
1033 | 1041 … | static get typeId () { |
1034 | 1042 … | return 299 |
@@ -1041,9 +1049,9 @@ | ||
1041 | 1049 … | hypervisor.registerContainer(Sub) |
1042 | 1050 … | |
1043 | 1051 … | const root = await hypervisor.createInstance(Root.typeId) |
1044 | 1052 … | const [portRef1, portRef2] = root.ports.createChannel() |
1045 | - root.ports.bind('first', portRef1) | |
1053 … | + await root.ports.bind('first', portRef1) | |
1046 | 1054 … | root.createInstance(Root.typeId, root.createMessage({ |
1047 | 1055 … | ports: [portRef2] |
1048 | 1056 … | })) |
1049 | 1057 … | |
@@ -1056,29 +1064,29 @@ | ||
1056 | 1064 … | }) |
1057 | 1065 … | |
1058 | 1066 … | tape('should remove multiple subgraphs', async t => { |
1059 | 1067 … | const expectedSr = { |
1060 | - '/': 'zdpuAo1qZHhS6obxbGbtvnUxkbAxA6VSbcjYiiTVNWTm37xQv' | |
1068 … | + '/': 'zdpuAohccQTxM82d8N6Q82z234nQskeQoJGJu3eAVmxoQwWde' | |
1061 | 1069 … | } |
1062 | 1070 … | class Root extends BaseContainer { |
1063 | - onMessage (m) { | |
1071 … | + async onMessage (m) { | |
1064 | 1072 … | if (m.ports.length) { |
1065 | 1073 … | const port = this.kernel.ports.get('test1') |
1066 | 1074 … | this.kernel.send(port, m) |
1067 | - this.kernel.ports.unbind('test1') | |
1068 | - this.kernel.ports.unbind('test2') | |
1075 … | + await this.kernel.ports.unbind('test1') | |
1076 … | + await this.kernel.ports.unbind('test2') | |
1069 | 1077 … | } else { |
1070 | 1078 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
1071 | 1079 … | this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
1072 | 1080 … | ports: [portRef2] |
1073 | 1081 … | })) |
1074 | - this.kernel.ports.bind('test1', portRef1) | |
1082 … | + await this.kernel.ports.bind('test1', portRef1) | |
1075 | 1083 … | |
1076 | 1084 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
1077 | 1085 … | this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
1078 | 1086 … | ports: [portRef4] |
1079 | 1087 … | })) |
1080 | - this.kernel.ports.bind('test2', portRef3) | |
1088 … | + await this.kernel.ports.bind('test2', portRef3) | |
1081 | 1089 … | this.kernel.send(portRef3, this.kernel.createMessage({ |
1082 | 1090 … | data: 'getChannel' |
1083 | 1091 … | })) |
1084 | 1092 … | } |
@@ -1088,15 +1096,15 @@ | ||
1088 | 1096 … | class Sub extends BaseContainer { |
1089 | 1097 … | onMessage (message) { |
1090 | 1098 … | if (message.data === 'getChannel') { |
1091 | 1099 … | const ports = this.kernel.ports.createChannel() |
1092 | - this.kernel.ports.bind('channel', ports[0]) | |
1093 | 1100 … | this.kernel.send(message.fromPort, this.kernel.createMessage({ |
1094 | 1101 … | data: 'bindPort', |
1095 | 1102 … | ports: [ports[1]] |
1096 | 1103 … | })) |
1104 … | + return this.kernel.ports.bind('channel', ports[0]) | |
1097 | 1105 … | } else if (message.data === 'bindPort') { |
1098 | - this.kernel.ports.bind('channel', message.ports[0]) | |
1106 … | + return this.kernel.ports.bind('channel', message.ports[0]) | |
1099 | 1107 … | } |
1100 | 1108 … | } |
1101 | 1109 … | static get typeId () { |
1102 | 1110 … | return 299 |
@@ -1110,9 +1118,9 @@ | ||
1110 | 1118 … | |
1111 | 1119 … | const root = await hypervisor.createInstance(Root.typeId) |
1112 | 1120 … | |
1113 | 1121 … | const [portRef1, portRef2] = root.ports.createChannel() |
1114 | - root.ports.bind('first', portRef1) | |
1122 … | + await root.ports.bind('first', portRef1) | |
1115 | 1123 … | root.createInstance(Root.typeId, root.createMessage({ |
1116 | 1124 … | ports: [portRef2] |
1117 | 1125 … | })) |
1118 | 1126 … | |
@@ -1152,17 +1160,17 @@ | ||
1152 | 1160 … | }) |
1153 | 1161 … | |
1154 | 1162 … | rootContainer.createInstance(testVMContainer.typeId, initMessage) |
1155 | 1163 … | |
1156 | - rootContainer.ports.bind('first', portRef1) | |
1164 … | + await rootContainer.ports.bind('first', portRef1) | |
1157 | 1165 … | const message = rootContainer.createMessage() |
1158 | 1166 … | const rPort = rootContainer.getResponsePort(message) |
1159 | 1167 … | const rPort2 = rootContainer.getResponsePort(message) |
1160 | 1168 … | |
1161 | 1169 … | t.equals(rPort2, rPort) |
1162 | 1170 … | |
1163 | 1171 … | rootContainer.send(portRef1, message) |
1164 | - rootContainer.ports.bind('response', rPort) | |
1172 … | + await rootContainer.ports.bind('response', rPort) | |
1165 | 1173 … | }) |
1166 | 1174 … | |
1167 | 1175 … | tape('start up', async t => { |
1168 | 1176 … | t.plan(1) |
Built with git-ssb-web