Commit ca90e13f859d9f1babea0d5f690290cf73a06138
fixed names in inbox.js
Signed-off-by: wanderer <mjbecze@gmail.com>wanderer committed on 11/19/2017, 1:34:55 AM
Parent: 26c361018ce2740027699d601b339a3001fea89b
Files changed
actor.js | changed |
inbox.js | changed |
index.js | changed |
scheduler.js | changed |
tests/index.js | changed |
actor.js | ||
---|---|---|
@@ -55,9 +55,8 @@ | ||
55 | 55 | // waits for the next message |
56 | 56 | async _startMessageLoop () { |
57 | 57 | // this ensure we only every have one loop running at a time |
58 | 58 | if (this.containerState !== 'running') { |
59 | - this.hypervisor.scheduler.update(this) | |
60 | 59 | this.containerState = 'running' |
61 | 60 | while (1) { |
62 | 61 | const message = await this.inbox.getNextMessage() |
63 | 62 | if (!message) break |
@@ -98,8 +97,9 @@ | ||
98 | 97 | let result |
99 | 98 | try { |
100 | 99 | result = await this.container[method](message) |
101 | 100 | } catch (e) { |
101 | + console.log(e) | |
102 | 102 | result = { |
103 | 103 | exception: true, |
104 | 104 | exceptionError: e |
105 | 105 | } |
inbox.js | ||
---|---|---|
@@ -41,12 +41,12 @@ | ||
41 | 41 | throw new Error('already getting next message') |
42 | 42 | } |
43 | 43 | |
44 | 44 | this._waitingTags = new Set(tags) |
45 | - this._queue.forEach(message => this._queueWaitingTags(message)) | |
45 | + this._queue.forEach(message => this._queueMessage(message)) | |
46 | 46 | |
47 | 47 | const message = await this.getNextMessage(timeout) |
48 | - // console.log('***', message) | |
48 | + this._waitingTagsQueue.forEach(message => this._queueMessage(message)) | |
49 | 49 | |
50 | 50 | delete this._waitingTags |
51 | 51 | return message |
52 | 52 | } |
@@ -67,9 +67,8 @@ | ||
67 | 67 | while (true) { |
68 | 68 | if (message && message._fromTicks < timeout) { |
69 | 69 | timeout = message._fromTicks |
70 | 70 | } |
71 | - // console.log(timeout, oldestTime) | |
72 | 71 | |
73 | 72 | if (oldestTime >= timeout) { |
74 | 73 | break |
75 | 74 | } |
@@ -109,20 +108,13 @@ | ||
109 | 108 | } |
110 | 109 | } |
111 | 110 | |
112 | 111 | _queueMessage (message) { |
113 | - if (this._waitingTags) { | |
114 | - this._queueWaitingTags(message) | |
115 | - } | |
116 | - binarySearchInsert(this._queue, messageArbiter, message) | |
117 | - } | |
118 | - | |
119 | - _queueWaitingTags (message) { | |
120 | - if (this._waitingTags.has(message.tag)) { | |
121 | - this._waitingAddresses.delete(message.tag) | |
112 | + if (this._waitingTags && this._waitingTags.has(message.tag)) { | |
113 | + this._waitingTags.delete(message.tag) | |
122 | 114 | binarySearchInsert(this._waitingTagsQueue, messageArbiter, message) |
123 | - // keep the taged waiting quueue pruned | |
124 | - this._waitingTagsQueue = [this._waitingTagsQueue[0]] | |
115 | + } else { | |
116 | + binarySearchInsert(this._queue, messageArbiter, message) | |
125 | 117 | } |
126 | 118 | } |
127 | 119 | } |
128 | 120 |
index.js | ||
---|---|---|
@@ -18,9 +18,9 @@ | ||
18 | 18 | async send (cap, message) { |
19 | 19 | cap = await Promise.resolve(cap) |
20 | 20 | const id = cap.destId |
21 | 21 | const instance = await this.getInstance(id) |
22 | - return instance.queue(message) | |
22 | + instance.queue(message) | |
23 | 23 | } |
24 | 24 | |
25 | 25 | // loads an instance of a container from the state |
26 | 26 | async _loadInstance (id) { |
scheduler.js | ||
---|---|---|
@@ -103,40 +103,42 @@ | ||
103 | 103 | |
104 | 104 | // checks outstanding waits to see if they can be resolved |
105 | 105 | _checkWaits () { |
106 | 106 | // if there are no running containers |
107 | - if (!this.instances.size) { | |
108 | - // clear any remanding waits | |
109 | - this._waits.forEach(wait => wait.resolve()) | |
110 | - this._waits = [] | |
111 | - } else { | |
112 | - // find the old container and see if to can resolve any of the waits | |
113 | - while (this._waits[0]) { | |
114 | - const wait = this._waits[0] | |
115 | - const least = this.leastNumberOfTicks(wait.id) | |
116 | - if (wait.ticks <= least) { | |
117 | - this._waits.shift() | |
118 | - wait.resolve() | |
119 | - this._running.add(wait.id) | |
120 | - } else { | |
121 | - break | |
107 | + if (!this._loadingInstances.size) { | |
108 | + if (!this.instances.size) { | |
109 | + // clear any remanding waits | |
110 | + this._waits.forEach(wait => wait.resolve()) | |
111 | + this._waits = [] | |
112 | + } else { | |
113 | + // find the old container and see if to can resolve any of the waits | |
114 | + while (this._waits[0]) { | |
115 | + const wait = this._waits[0] | |
116 | + const least = this.leastNumberOfTicks(wait.id) | |
117 | + if (wait.ticks <= least) { | |
118 | + this._waits.shift() | |
119 | + wait.resolve() | |
120 | + this._running.add(wait.id) | |
121 | + } else { | |
122 | + break | |
123 | + } | |
122 | 124 | } |
123 | - } | |
124 | 125 | |
125 | - if (!this._running.size) { | |
126 | - // if there are no containers running find the oldest wait and update | |
127 | - // the oldest containers to it ticks | |
128 | - const oldest = this._waits[0].ticks | |
129 | - for (let instance of this.instances) { | |
130 | - instance = instance[1] | |
131 | - if (instance.ticks > oldest) { | |
132 | - break | |
133 | - } else { | |
134 | - instance.ticks = oldest | |
135 | - this._update(instance) | |
126 | + if (!this._running.size) { | |
127 | + // if there are no containers running find the oldest wait and update | |
128 | + // the oldest containers to it ticks | |
129 | + const oldest = this._waits[0].ticks | |
130 | + for (let instance of this.instances) { | |
131 | + instance = instance[1] | |
132 | + if (instance.ticks > oldest) { | |
133 | + break | |
134 | + } else { | |
135 | + instance.ticks = oldest | |
136 | + this._update(instance) | |
137 | + } | |
136 | 138 | } |
139 | + return this._checkWaits() | |
137 | 140 | } |
138 | - return this._checkWaits() | |
139 | 141 | } |
140 | 142 | } |
141 | 143 | } |
142 | 144 | } |
tests/index.js | ||
---|---|---|
@@ -478,13 +478,12 @@ | ||
478 | 478 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
479 | 479 | t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0) |
480 | 480 | }) |
481 | 481 | |
482 | -tape.skip('basic tagged caps', async t => { | |
483 | - t.plan(4) | |
484 | - let message | |
482 | +tape('basic tagged caps', async t => { | |
483 | + t.plan(5) | |
485 | 484 | const expectedState = { |
486 | - '/': Buffer.from('fc935489953ed357f06171dd23439d83190b3a1b', 'hex') | |
485 | + '/': Buffer.from('ef403643f292108fe9edc1700d80a7bf2402e7a0', 'hex') | |
487 | 486 | } |
488 | 487 | |
489 | 488 | const tree = new RadixTree({ |
490 | 489 | db: db |
@@ -495,18 +494,16 @@ | ||
495 | 494 | t.true(m, 'should recive first message') |
496 | 495 | const rCap = this.kernel.mintCap(1) |
497 | 496 | const message = new Message() |
498 | 497 | message.responseCap = rCap |
499 | - console.log('here') | |
500 | - this.kernel.send(m.caps[0], message) | |
498 | + await this.kernel.send(m.caps[0], message) | |
501 | 499 | const rMessage = await this.kernel.inbox.waitOnTag([1], 44) |
502 | 500 | t.true(rMessage, 'should recive a response message') |
503 | 501 | } |
504 | 502 | } |
505 | 503 | |
506 | 504 | class testVMContainerB extends BaseContainer { |
507 | 505 | onMessage (m) { |
508 | - console.log('&&&&&&&&&&&&&&&&&&&&&&&&&&') | |
509 | 506 | t.true(m, 'should recive a message') |
510 | 507 | } |
511 | 508 | |
512 | 509 | static get typeId () { |
Built with git-ssb-web