git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 1a02908906ad592224398890dbe31da370639340

Cleanup scheduler documentation & _checkWaits

sdtsui committed on 11/22/2017, 12:43:11 AM
Parent: 47cdaf541c5fb70cd51572ef2e40fda377cfe086

Files changed

package-lock.jsonchanged
scheduler.jschanged
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 325800 bytes
New file size: 342929 bytes
scheduler.jsView
@@ -7,10 +7,9 @@
77 }
88
99 module.exports = class Scheduler {
1010 /**
11- * The Scheduler manages the run cycle of Actors and figures out which
12- * order they should run in
11 + * the Scheduler keeps track of which containers are instantiated, running, and waiting for a message
1312 */
1413 constructor () {
1514 this._waits = []
1615 this._running = new Set()
@@ -71,8 +70,9 @@
7170 * @return {Promise}
7271 */
7372 wait (ticks, id) {
7473 this._running.delete(id)
74 +
7575 return new Promise((resolve, reject) => {
7676 binarySearchInsert(this._waits, comparator, {
7777 ticks: ticks,
7878 resolve: resolve,
@@ -85,65 +85,68 @@
8585 /**
8686 * returns the oldest container's ticks
8787 * @return {integer}
8888 */
89- leastNumberOfTicks (exculde) {
89 + leastNumberOfTicks (exclude) {
9090 let ticks = 0
9191 for (const instance of this.instances) {
9292 ticks = instance[1].ticks
93- if (instance[1].id !== exculde) {
93 + if (instance[1].id !== exclude) {
9494 return ticks
9595 }
9696 }
97 +
9798 return ticks
9899 }
99100
100101 // checks outstanding waits to see if they can be resolved
101102 async _checkWaits () {
102103 if (this._checkingWaits) {
103104 return
104- } else {
105- this._checkingWaits = true
106- // wait to check waits untill all the instances are done loading
107- await [...this._loadingInstances.values()]
108105 }
109- // if there are no running containers
106 + this._checkingWaits = true
107 +
108 + // wait to check waits until all the instances are done loading
109 + await [...this._loadingInstances.values()]
110 +
111 + // if there are no instances, clear any remaining waits
110112 if (!this.instances.size) {
111- // clear any remanding waits
112113 this._waits.forEach(wait => wait.resolve())
113114 this._waits = []
114115 this._checkingWaits = false
115- } else {
116- // find the old container and see if to can resolve any of the waits
117- while (this._waits[0]) {
118- const wait = this._waits[0]
119- const least = this.leastNumberOfTicks(wait.id)
120- if (wait.ticks <= least) {
121- this._waits.shift()
122- wait.resolve()
123- this._running.add(wait.id)
124- } else {
116 +
117 + return
118 + }
119 +
120 + // find the old container, see if any of the waits can be resolved
121 + while (this._waits[0]) {
122 + const wait = this._waits[0]
123 + const least = this.leastNumberOfTicks(wait.id)
124 + if (wait.ticks <= least) {
125 + this._waits.shift()
126 + wait.resolve()
127 + this._running.add(wait.id)
128 + } else {
129 + break
130 + }
131 + }
132 +
133 + // if there are no containers running find the oldest wait
134 + // and update the oldest containers to its ticks
135 + if (!this._running.size && this._waits.length) {
136 + const oldest = this._waits[0].ticks
137 + for (let instance of this.instances) {
138 + instance = instance[1]
139 + if (instance.ticks > oldest) {
125140 break
126141 }
142 + instance.ticks = oldest
143 + this._update(instance)
127144 }
145 + this._checkingWaits = false
128146
129- if (!this._running.size && this._waits.length) {
130- // if there are no containers running find the oldest wait and update
131- // the oldest containers to it ticks
132- const oldest = this._waits[0].ticks
133- for (let instance of this.instances) {
134- instance = instance[1]
135- if (instance.ticks > oldest) {
136- break
137- } else {
138- instance.ticks = oldest
139- this._update(instance)
140- }
141- }
142- this._checkingWaits = false
143- return this._checkWaits()
144- } else {
145- this._checkingWaits = false
146- }
147 + return this._checkWaits()
147148 }
149 +
150 + this._checkingWaits = false
148151 }
149152 }

Built with git-ssb-web