git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 46248da0b2e047c143b387676430c8d2d27cf4a3

ready for the dive

wanderer committed on 6/28/2017, 4:31:05 AM
Parent: f2c989b4dce29265b4c17a2cde93c68a0b742edc

Files changed

index.jschanged
scheduler.jschanged
index.jsView
@@ -16,9 +16,8 @@
1616 this.scheduler = new Scheduler()
1717 this.state = state
1818 this._containerTypes = {}
1919 this._nodesToCheck = new Set()
20- this._loadingInstances = new Map()
2120 }
2221
2322 /**
2423 * add a potaintail node in the state graph to check for garbage collection
@@ -62,9 +61,8 @@
6261 id: id
6362 })
6463
6564 // save the newly created instance
66- this.scheduler.releaseLock(lock)
6765 this.scheduler.update(exoInterface)
6866 return exoInterface
6967 }
7068
@@ -73,20 +71,19 @@
7371 * @param {string} id - the containers ID
7472 * @returns {Promise}
7573 */
7674 getInstance (id) {
77- let instance = this.scheduler.getInstance(id) || this._loadingInstances.get(id)
75+ let instance = this.scheduler.getInstance(id)
7876 if (instance) {
79- // console.log('have instance', id)
8077 return instance
8178 } else {
82- const lock = this.scheduler.getLock()
83- const promise = this._loadInstance(id, lock)
79+ const promise = this._loadInstance(id, id)
8480 promise.then(() => {
85- this._loadingInstances.delete(id)
81+ this.scheduler._loadingInstances.delete(id)
82+ this.scheduler.releaseLock(id)
8683 })
87-
88- this._loadingInstances.set(id, promise)
84+ this.scheduler.getLock(id, promise)
85+ this.scheduler._loadingInstances.set(id, promise)
8986 return promise
9087 }
9188 }
9289
@@ -102,21 +99,23 @@
10299 */
103100 async createInstance (type, code, entryPorts = [], id = {nonce: 0, parent: null}) {
104101 // create a lock to prevent the scheduler from reloving waits before the
105102 // new container is loaded
106- const lock = this.scheduler.getLock()
107- id = await this.getHashFromObj(id)
103+ this.scheduler.getLock(id)
104+ const idHash = await this.getHashFromObj(id)
108105 const state = {
109106 nonce: [0],
110107 ports: {},
111108 type: type,
112109 code: code
113110 }
114111
115112 // save the container in the state
116- await this.graph.set(this.state, id, state)
113+ await this.graph.set(this.state, idHash, state)
117114 // create the container instance
118- const exoInterface = await this._loadInstance(id, lock)
115+ const exoInterface = await this._loadInstance(idHash, id)
116+
117+ this.scheduler.releaseLock(id)
119118 // send the intialization message
120119 exoInterface.queue(null, new Message({
121120 ports: entryPorts
122121 }))
scheduler.jsView
@@ -11,14 +11,14 @@
1111 module.exports = class Scheduler {
1212 constructor () {
1313 this._waits = []
1414 this._running = new Set()
15+ this._loadingInstances = new Map()
1516 this.instances = new Map()
1617 this.locks = new Set()
1718 }
1819
19- getLock () {
20- const id = Symbol('lock')
20+ getLock (id) {
2121 this.locks.add(id)
2222 return id
2323 }
2424
@@ -39,9 +39,9 @@
3939 this.instances = new Map(instanceArray)
4040 }
4141
4242 getInstance (id) {
43- return this.instances.get(id)
43+ return this.instances.get(id) || this._loadingInstances.get(id)
4444 }
4545
4646 done (instance) {
4747 this._running.delete(instance.id)

Built with git-ssb-web