Commit 3146cb3249c2ab000ed44d4712910ff42fd0d5c1
update the actors age in inbox
wanderer committed on 12/11/2017, 10:49:38 PMParent: bc308a00381563261f0f7ecf1d231d19e2dfbc52
Files changed
actor.js | changed |
inbox.js | changed |
actor.js | ||
---|---|---|
@@ -70,14 +70,8 @@ | ||
70 | 70 | while (1) { |
71 | 71 | const message = await this.inbox.nextMessage() |
72 | 72 | if (!message) break |
73 | 73 | |
74 | - // if the message we recived had more ticks then we currently have then | |
75 | - // update it | |
76 | - if (message._fromTicks > this.ticks) { | |
77 | - this.ticks = message._fromTicks | |
78 | - this.hypervisor.scheduler.update(this) | |
79 | - } | |
80 | 74 | // run the next message |
81 | 75 | await this.runMessage(message) |
82 | 76 | // wait for state ops to finish |
83 | 77 | await this.state.done() |
@@ -129,11 +123,8 @@ | ||
129 | 123 | * @param {String} method - which method to run |
130 | 124 | * @returns {Promise} |
131 | 125 | */ |
132 | 126 | async runMessage (message, method = 'onMessage') { |
133 | - const responseCap = message.responseCap | |
134 | - delete message.responseCap | |
135 | - | |
136 | 127 | let result |
137 | 128 | try { |
138 | 129 | result = await this.container[method](message) |
139 | 130 | } catch (e) { |
@@ -143,10 +134,10 @@ | ||
143 | 134 | exceptionError: e |
144 | 135 | } |
145 | 136 | } |
146 | 137 | |
147 | - if (responseCap) { | |
148 | - this.send(responseCap, new Message({ | |
138 | + if (message.responseCap) { | |
139 | + this.send(message.responseCap, new Message({ | |
149 | 140 | data: result |
150 | 141 | })) |
151 | 142 | } |
152 | 143 | } |
inbox.js | ||
---|---|---|
@@ -90,12 +90,25 @@ | ||
90 | 90 | timeout += this.actor.ticks |
91 | 91 | let oldestTime = this.hypervisor.scheduler.leastNumberOfTicks(this.actor.id) |
92 | 92 | |
93 | 93 | while (true) { |
94 | - if (message && message._fromTicks < timeout) { | |
95 | - timeout = message._fromTicks | |
94 | + if (message) { | |
95 | + // if the message we recived had more ticks then we currently have then | |
96 | + // update our ticks to it, since we jumped forward in time | |
97 | + if (message._fromTicks > this.actor.ticks) { | |
98 | + this.actor.ticks = message._fromTicks | |
99 | + this.hypervisor.scheduler.update(this.actor) | |
100 | + } | |
101 | + | |
102 | + // if there is a message that is "older" then the timeout, the lower | |
103 | + // the timeout to the oldest message | |
104 | + if (message._fromTicks < timeout) { | |
105 | + timeout = message._fromTicks | |
106 | + } | |
96 | 107 | } |
97 | 108 | |
109 | + // if all actors are "older" then the time out then stop waiting for messages | |
110 | + // since we konw that we can not receive one | |
98 | 111 | if (oldestTime >= timeout) { |
99 | 112 | break |
100 | 113 | } |
101 | 114 |
Built with git-ssb-web