git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 4c6125763fffeac43ae5302bb5541ac7f124c0a3

rename

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 1/19/2018, 5:11:34 AM
Parent: 5663a9c6ffec1a589222e24ac20e696eb4ff1f6a

Files changed

index.jschanged
scheduler.jschanged
index.jsView
@@ -21,13 +21,12 @@
2121 * @returns {Promise} a promise that resolves once the receiving container is loaded
2222 */
2323 async send (message) {
2424 const id = message.funcRef.destId
25- const instance = await this.getActor(id)
26- instance.queue(message)
25+ const actor = await this.getActor(id)
26+ actor.queue(message)
2727 }
2828
29- // loads an instance of a container from the state
3029 async _loadActor (id) {
3130 const state = await this.tree.getSubTree(id)
3231 const {type, nonce} = Actor.deserializeMetaData(state.root['/'][3])
3332 const container = this._containerTypes[type]
@@ -52,9 +51,9 @@
5251 * @param {string} id - the actor's ID
5352 * @returns {Promise}
5453 */
5554 async getActor (id) {
56- let actor = this.scheduler.getInstance(id)
55+ let actor = this.scheduler.getActor(id)
5756 if (!actor) {
5857 const resolve = this.scheduler.lock(id)
5958 actor = await this._loadActor(id)
6059 resolve(actor)
scheduler.jsView
@@ -12,9 +12,9 @@
1212 */
1313 constructor () {
1414 this._waits = []
1515 this._running = new Set()
16- this.instances = new SortedMap(comparator)
16+ this.actors = new SortedMap(comparator)
1717 }
1818
1919 /**
2020 * locks the scheduler from clearing waits untill the lock is resolved
@@ -27,46 +27,46 @@
2727 const p = new Promise((resolve, reject) => {
2828 r = resolve
2929 })
3030 p.ticks = 0
31- this.instances.set(id, p)
31+ this.actors.set(id, p)
3232 this._running.add(id)
3333 return r
3434 }
3535
3636 /**
37- * updates an instance with a new tick count
38- * @param {Object} instance - an actor instance
37+ * updates an actor with a new tick count
38+ * @param {Object} actor - an actor instance
3939 */
40- update (instance) {
41- this._update(instance)
42- this._running.add(instance.id.toString('hex'))
40+ update (actor) {
41+ this._update(actor)
42+ this._running.add(actor.id.toString('hex'))
4343 this._checkWaits()
4444 }
4545
46- _update (instance) {
47- this.instances.delete(instance.id.toString('hex'))
48- this.instances.set(instance.id.toString('hex'), instance)
46+ _update (actor) {
47+ this.actors.delete(actor.id.toString('hex'))
48+ this.actors.set(actor.id.toString('hex'), actor)
4949 }
5050
5151 /**
5252 * returns an Actor instance
5353 * @param {String} id
5454 * @return {Object}
5555 */
56- getInstance (id) {
56+ getActor (id) {
5757 id = id.toString('hex')
58- return this.instances.get(id)
58+ return this.actors.get(id)
5959 }
6060
6161 /**
62- * deletes an instance from the scheduler
62+ * deletes an actor from the scheduler
6363 * @param {String} id - the containers id
6464 */
6565 done (id) {
6666 id = id.toString('hex')
6767 this._running.delete(id)
68- this.instances.delete(id)
68+ this.actors.delete(id)
6969 this._checkWaits()
7070 }
7171
7272 /**
@@ -97,11 +97,11 @@
9797 * @return {integer}
9898 */
9999 leastNumberOfTicks (exclude) {
100100 let ticks = Infinity
101- for (const instance of this.instances) {
102- ticks = instance[1].ticks
103- if (instance[1].id !== exclude) {
101+ for (const actor of this.actors) {
102+ ticks = actor[1].ticks
103+ if (actor[1].id !== exclude) {
104104 return ticks
105105 }
106106 }
107107
@@ -110,16 +110,16 @@
110110
111111 // checks outstanding waits to see if they can be resolved
112112 _checkWaits () {
113113 // if there are no instances, clear any remaining waits
114- if (!this.instances.size) {
114+ if (!this.actors.size) {
115115 // console.log('here', this._waits)
116116 this._waits.forEach(wait => wait.resolve())
117117 this._waits = []
118118 return
119119 }
120120
121- // find the old container, see if any of the waits can be resolved
121+ // find the oldest container, see if any of the waits can be resolved
122122 while (this._waits[0]) {
123123 const wait = this._waits[0]
124124 const least = this.leastNumberOfTicks(wait.id)
125125 if (wait.ticks <= least) {
@@ -134,15 +134,15 @@
134134 // if there are no containers running find the oldest wait
135135 // and update the oldest containers to its ticks
136136 if (!this._running.size && this._waits.length) {
137137 const oldest = this._waits[0].ticks
138- for (let instance of this.instances) {
139- instance = instance[1]
140- if (instance.ticks > oldest) {
138+ for (let actor of this.actors) {
139+ actor = actor[1]
140+ if (actor.ticks > oldest) {
141141 break
142142 }
143- instance.ticks = oldest
144- this._update(instance)
143+ actor.ticks = oldest
144+ this._update(actor)
145145 }
146146 return this._checkWaits()
147147 }
148148 }

Built with git-ssb-web