index.jsView |
---|
16 | 16 | this.scheduler = new Scheduler() |
17 | 17 | this.state = state |
18 | 18 | this._containerTypes = {} |
19 | 19 | this._nodesToCheck = new Set() |
20 | | - this._loadingInstances = new Map() |
21 | 20 | } |
22 | 21 | |
23 | 22 | |
24 | 23 | * add a potaintail node in the state graph to check for garbage collection |
62 | 61 | id: id |
63 | 62 | }) |
64 | 63 | |
65 | 64 | |
66 | | - this.scheduler.releaseLock(lock) |
67 | 65 | this.scheduler.update(exoInterface) |
68 | 66 | return exoInterface |
69 | 67 | } |
70 | 68 | |
73 | 71 | * @param {string} id - the containers ID |
74 | 72 | * @returns {Promise} |
75 | 73 | */ |
76 | 74 | getInstance (id) { |
77 | | - let instance = this.scheduler.getInstance(id) || this._loadingInstances.get(id) |
| 75 | + let instance = this.scheduler.getInstance(id) |
78 | 76 | if (instance) { |
79 | | - |
80 | 77 | return instance |
81 | 78 | } else { |
82 | | - const lock = this.scheduler.getLock() |
83 | | - const promise = this._loadInstance(id, lock) |
| 79 | + const promise = this._loadInstance(id, id) |
84 | 80 | promise.then(() => { |
85 | | - this._loadingInstances.delete(id) |
| 81 | + this.scheduler._loadingInstances.delete(id) |
| 82 | + this.scheduler.releaseLock(id) |
86 | 83 | }) |
87 | | - |
88 | | - this._loadingInstances.set(id, promise) |
| 84 | + this.scheduler.getLock(id, promise) |
| 85 | + this.scheduler._loadingInstances.set(id, promise) |
89 | 86 | return promise |
90 | 87 | } |
91 | 88 | } |
92 | 89 | |
102 | 99 | */ |
103 | 100 | async createInstance (type, code, entryPorts = [], id = {nonce: 0, parent: null}) { |
104 | 101 | |
105 | 102 | |
106 | | - const lock = this.scheduler.getLock() |
107 | | - id = await this.getHashFromObj(id) |
| 103 | + this.scheduler.getLock(id) |
| 104 | + const idHash = await this.getHashFromObj(id) |
108 | 105 | const state = { |
109 | 106 | nonce: [0], |
110 | 107 | ports: {}, |
111 | 108 | type: type, |
112 | 109 | code: code |
113 | 110 | } |
114 | 111 | |
115 | 112 | |
116 | | - await this.graph.set(this.state, id, state) |
| 113 | + await this.graph.set(this.state, idHash, state) |
117 | 114 | |
118 | | - const exoInterface = await this._loadInstance(id, lock) |
| 115 | + const exoInterface = await this._loadInstance(idHash, id) |
| 116 | + |
| 117 | + this.scheduler.releaseLock(id) |
119 | 118 | |
120 | 119 | exoInterface.queue(null, new Message({ |
121 | 120 | ports: entryPorts |
122 | 121 | })) |