git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 77a97926a01c38ec889ed82e584cdf833cad6a31

keep track of the current message

wanderer committed on 12/14/2017, 11:10:44 PM
Parent: a9dfa953b57feff50f135a8191e5ee17d3adfc83

Files changed

actor.jschanged
inbox.jschanged
index.jschanged
tests/index.jschanged
actor.jsView
@@ -43,9 +43,13 @@
4343 * @param {object} message
4444 */
4545 queue (message) {
4646 this.inbox.queue(message)
47- this._startMessageLoop()
47+
48+ if (!this.running) {
49+ this.running = true
50+ this._startMessageLoop()
51+ }
4852 }
4953
5054 /**
5155 * runs the creation routine for the actor
@@ -53,50 +57,46 @@
5357 * @returns {Promise}
5458 */
5559 create (message) {
5660 this.running = true
61+ this.inbox.currentMessage = message
5762 return this.runMessage(message, 'onCreation').then(() => {
58- this.running = false
5963 this._startMessageLoop()
6064 })
6165 }
6266
6367 // waits for the next message
6468 async _startMessageLoop () {
6569 // this ensure we only every have one loop running at a time
70+ while (1) {
71+ const message = await this.inbox.nextMessage(0, true)
72+ if (!message) break
73+
74+ // run the next message
75+ await this.runMessage(message)
76+ }
77+ this.running = false
78+ // wait for state ops to finish
79+ await this.state.done()
6680 if (!this.running) {
67- this.running = true
68- while (1) {
69- const message = await this.inbox.nextMessage(0, true)
70- if (!message) break
71-
72- // run the next message
73- await this.runMessage(message)
74- // wait for state ops to finish
75- await this.state.done()
76- }
77-
78- this.running = false
7981 this.container.onIdle()
8082 }
8183 }
8284
8385 serializeMetaData () {
84- return Actor.serializeMetaData(this.type, this.transparent, this.nonce)
86+ return Actor.serializeMetaData(this.type, this.nonce)
8587 }
8688
87- static serializeMetaData (type, transparent = 0, nonce = 0) {
89+ static serializeMetaData (type, nonce = 0) {
8890 const p = new Pipe()
8991 leb128.write(type, p)
90- p.write(Buffer.from([0]))
9192 leb128.write(nonce, p)
9293 return p.buffer
9394 }
9495
9596 static deserializeMetaData (buffer) {
9697 const pipe = new Pipe(buffer)
9798 const type = leb128.read(pipe)
98- pipe.read(1)
9999 const nonce = leb128.read(pipe)
100100 return {
101101 nonce,
102102 type
@@ -179,9 +179,8 @@
179179 */
180180 send (cap, message) {
181181 message._fromTicks = this.ticks
182182 message._fromId = this.id
183- message.tag = cap.tag
184183
185184 return this.hypervisor.send(cap, message)
186185 }
187186 }
inbox.jsView
@@ -122,9 +122,10 @@
122122 })
123123 ])
124124 oldestTime = this.hypervisor.scheduler.leastNumberOfTicks(this.actor.id)
125125 }
126- return this._deQueueMessage()
126+ this.currentMessage = this._deQueueMessage()
127+ return this.currentMessage
127128 }
128129
129130 // returns a promise that resolve when a message older then the given message
130131 // is recived
index.jsView
@@ -20,8 +20,9 @@
2020 * @param {Object} message - the [message](https://github.com/primea/js-primea-message) to send
2121 * @returns {Promise} a promise that resolves once the receiving container is loaded
2222 */
2323 async send (cap, message) {
24+ message.tag = cap.tag
2425 const id = cap.destId
2526 const instance = await this.getActor(id)
2627 instance.queue(message)
2728 }
tests/index.jsView
@@ -17,9 +17,9 @@
1717 tape('basic', async t => {
1818 t.plan(2)
1919 let message
2020 const expectedState = {
21- '/': Buffer.from('a364c55f9993e0bc63f7155d5eb661ae9ad769d9', 'hex')
21+ '/': Buffer.from('926de6b7eb39cfa8d7f8a44d1ef191d3bcb765a7', 'hex')
2222 }
2323
2424 const tree = new RadixTree({
2525 db: db
@@ -46,9 +46,9 @@
4646 tape('two communicating actors', async t => {
4747 t.plan(2)
4848 let message
4949 const expectedState = {
50- '/': Buffer.from('9e8d5671e2c7d167e03784e5d9ec36e15747ad95', 'hex')
50+ '/': Buffer.from('a4c7ceacd8c867ae1d0b472d8bffa3cb10048331', 'hex')
5151 }
5252
5353 const tree = new RadixTree({
5454 db: db
@@ -87,9 +87,9 @@
8787 tape('three communicating actors', async t => {
8888 t.plan(3)
8989 let message
9090 const expectedState = {
91- '/': Buffer.from('840607eafe779858648d3311039f986e68f4752e', 'hex')
91+ '/': Buffer.from('4633ac4b9f8212e501b6c56906039ec081fbe5a3', 'hex')
9292 }
9393
9494 const tree = new RadixTree({
9595 db: db
@@ -132,9 +132,9 @@
132132 tape('three communicating actors, with tick counting', async t => {
133133 t.plan(3)
134134 let message
135135 const expectedState = {
136- '/': Buffer.from('840607eafe779858648d3311039f986e68f4752e', 'hex')
136+ '/': Buffer.from('4633ac4b9f8212e501b6c56906039ec081fbe5a3', 'hex')
137137 }
138138
139139 const tree = new RadixTree({
140140 db: db
@@ -182,9 +182,9 @@
182182 tape('response caps', async t => {
183183 t.plan(3)
184184 let message
185185 const expectedState = {
186- '/': Buffer.from('9e8d5671e2c7d167e03784e5d9ec36e15747ad95', 'hex')
186+ '/': Buffer.from('a4c7ceacd8c867ae1d0b472d8bffa3cb10048331', 'hex')
187187 }
188188
189189 const tree = new RadixTree({
190190 db: db
@@ -229,9 +229,9 @@
229229 tape('response caps for errors', async t => {
230230 t.plan(3)
231231 let message
232232 const expectedState = {
233- '/': Buffer.from('9e8d5671e2c7d167e03784e5d9ec36e15747ad95', 'hex')
233+ '/': Buffer.from('a4c7ceacd8c867ae1d0b472d8bffa3cb10048331', 'hex')
234234 }
235235
236236 const tree = new RadixTree({
237237 db: db
@@ -276,9 +276,9 @@
276276 tape('actor creation', async t => {
277277 t.plan(2)
278278 let message
279279 const expectedState = {
280- '/': Buffer.from('b19c67aea0ff97e96df6e2aacbd45b1bd260af30', 'hex')
280+ '/': Buffer.from('f47377a763c91247e62138408d706a09bccaaf36', 'hex')
281281 }
282282
283283 const tree = new RadixTree({
284284 db: db
@@ -320,9 +320,9 @@
320320
321321 tape('simple message arbiter test', async t => {
322322 t.plan(4)
323323 const expectedState = {
324- '/': Buffer.from('9e8d5671e2c7d167e03784e5d9ec36e15747ad95', 'hex')
324+ '/': Buffer.from('a4c7ceacd8c867ae1d0b472d8bffa3cb10048331', 'hex')
325325 }
326326
327327 const tree = new RadixTree({
328328 db: db
@@ -382,9 +382,9 @@
382382 tape('arbiter test for id comparision', async t => {
383383 t.plan(4)
384384 let message
385385 const expectedState = {
386- '/': Buffer.from('840607eafe779858648d3311039f986e68f4752e', 'hex')
386+ '/': Buffer.from('4633ac4b9f8212e501b6c56906039ec081fbe5a3', 'hex')
387387 }
388388
389389 const tree = new RadixTree({
390390 db: db
@@ -443,9 +443,9 @@
443443
444444 tape('basic tagged caps', async t => {
445445 t.plan(4)
446446 const expectedState = {
447- '/': Buffer.from('d4291da4536544bf90aa473a1148cb29f913d078', 'hex')
447+ '/': Buffer.from('b8eb399087a990e30373e954b627a9512c9af40b', 'hex')
448448 }
449449
450450 const tree = new RadixTree({
451451 db: db
@@ -488,9 +488,9 @@
488488
489489 tape('return while waiting for tag', async t => {
490490 t.plan(4)
491491 const expectedState = {
492- '/': Buffer.from('d4291da4536544bf90aa473a1148cb29f913d078', 'hex')
492+ '/': Buffer.from('b8eb399087a990e30373e954b627a9512c9af40b', 'hex')
493493 }
494494
495495 const tree = new RadixTree({
496496 db: db
@@ -536,9 +536,9 @@
536536
537537 tape('trying to listen for caps more then once', async t => {
538538 t.plan(4)
539539 const expectedState = {
540- '/': Buffer.from('d4291da4536544bf90aa473a1148cb29f913d078', 'hex')
540+ '/': Buffer.from('b8eb399087a990e30373e954b627a9512c9af40b', 'hex')
541541 }
542542
543543 const tree = new RadixTree({
544544 db: db
@@ -586,9 +586,9 @@
586586
587587 tape('multple messages to restore on waiting for tags', async t => {
588588 t.plan(6)
589589 const expectedState = {
590- '/': Buffer.from('b5c0822ccb21bbaa2ad8069c4dcd18add7d6e2d1', 'hex')
590+ '/': Buffer.from('b2025e9430f0ce3a53767a36124fa622f782a38f', 'hex')
591591 }
592592
593593 const tree = new RadixTree({
594594 db: db
@@ -646,9 +646,9 @@
646646
647647 tape('multple messages to backup on waiting for tags', async t => {
648648 t.plan(6)
649649 const expectedState = {
650- '/': Buffer.from('b5c0822ccb21bbaa2ad8069c4dcd18add7d6e2d1', 'hex')
650+ '/': Buffer.from('b2025e9430f0ce3a53767a36124fa622f782a38f', 'hex')
651651 }
652652
653653 const tree = new RadixTree({
654654 db: db
@@ -705,9 +705,9 @@
705705
706706 tape('multple messages, but single tag', async t => {
707707 t.plan(6)
708708 const expectedState = {
709- '/': Buffer.from('b5c0822ccb21bbaa2ad8069c4dcd18add7d6e2d1', 'hex')
709+ '/': Buffer.from('b2025e9430f0ce3a53767a36124fa622f782a38f', 'hex')
710710 }
711711
712712 const tree = new RadixTree({
713713 db: db
@@ -764,9 +764,9 @@
764764
765765 tape('deadlock test', async t => {
766766 t.plan(7)
767767 const expectedState = {
768- '/': Buffer.from('f290945ad63dd06b9ada924fa5149df4a0a32f53', 'hex')
768+ '/': Buffer.from('54f55756d0255d849e6878cc706f4c1565396e5c', 'hex')
769769 }
770770
771771 const tree = new RadixTree({
772772 db: db

Built with git-ssb-web