git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 71fa8ce31e076f693c68131f4ea2ee4b49379c07

fix waiting bug

wanderer committed on 1/7/2018, 10:21:28 PM
Parent: c77c7618fb3abd31a3d1b797af55b9f21a318173

Files changed

inbox.jschanged
scheduler.jschanged
inbox.jsView
@@ -81,21 +81,18 @@
8181 throw new Error('already waiting for next message')
8282 }
8383
8484 let message = this._getOldestMessage()
85+ if (message) {
86+ timeout = message._fromTicks
87+ } else {
88+ timeout += this.actor.ticks
89+ }
8590
86- timeout += this.actor.ticks
8791 let oldestTime = this.hypervisor.scheduler.leastNumberOfTicks(this.actor.id)
8892
8993 while (true) {
9094 if (message) {
91- // if the message we recived had more ticks then we currently have then
92- // update our ticks to it, since we jumped forward in time
93- if (message._fromTicks > this.actor.ticks) {
94- this.actor.ticks = message._fromTicks
95- this.hypervisor.scheduler.update(this.actor)
96- }
97-
9895 // if there is a message that is "older" then the timeout, the lower
9996 // the timeout to the oldest message
10097 if (message._fromTicks < timeout) {
10198 timeout = message._fromTicks
@@ -118,8 +115,14 @@
118115 ])
119116 oldestTime = this.hypervisor.scheduler.leastNumberOfTicks(this.actor.id)
120117 }
121118 this._gettingNextMessage = false
119+ // if the message we recived had more ticks then we currently have then
120+ // update our ticks to it, since we jumped forward in time
121+ if (message && message._fromTicks > this.actor.ticks) {
122+ this.actor.ticks = message._fromTicks
123+ this.hypervisor.scheduler.update(this.actor)
124+ }
122125 return this._deQueueMessage()
123126 }
124127
125128 // returns a promise that resolve when a message older then the given message
scheduler.jsView
@@ -21,8 +21,9 @@
2121 * @param {string} id
2222 * @return {function} the resolve function to call once it to unlock
2323 */
2424 lock (id) {
25+ id = id.toString('hex')
2526 let r
2627 const p = new Promise((resolve, reject) => {
2728 r = resolve
2829 })
@@ -36,33 +37,34 @@
3637 * updates an instance with a new tick count
3738 * @param {Object} instance - an actor instance
3839 */
3940 update (instance) {
40- this._waits = this._waits.filter(wait => wait.id !== instance.id)
4141 this._update(instance)
42- this._running.add(instance.id)
42+ this._running.add(instance.id.toString('hex'))
4343 this._checkWaits()
4444 }
4545
4646 _update (instance) {
47- this.instances.delete(instance.id)
48- this.instances.set(instance.id, instance)
47+ this.instances.delete(instance.id.toString('hex'))
48+ this.instances.set(instance.id.toString('hex'), instance)
4949 }
5050
5151 /**
5252 * returns an Actor instance
5353 * @param {String} id
5454 * @return {Object}
5555 */
5656 getInstance (id) {
57+ id = id.toString('hex')
5758 return this.instances.get(id)
5859 }
5960
6061 /**
6162 * deletes an instance from the scheduler
6263 * @param {String} id - the containers id
6364 */
6465 done (id) {
66+ id = id.toString('hex')
6567 this._running.delete(id)
6668 this.instances.delete(id)
6769 this._checkWaits()
6870 }
@@ -74,9 +76,12 @@
7476 * @param {string} id - optional id of the container that is waiting
7577 * @return {Promise}
7678 */
7779 wait (ticks, id) {
78- this._running.delete(id)
80+ if (id) {
81+ id = id.toString('hex')
82+ this._running.delete(id)
83+ }
7984
8085 return new Promise((resolve, reject) => {
8186 binarySearchInsert(this._waits, comparator, {
8287 ticks: ticks,

Built with git-ssb-web