Commit 9ff63d468409beadacd8b12f0eddf4160cecf81e
generelize ports
wanderer committed on 5/22/2017, 9:27:33 PMParent: ea9456b0cd659d6f9a4f7a039e4207d594c292e4
Files changed
exoInterface.js | changed |
portManager.js | changed |
exoInterface.js | ||
---|---|---|
@@ -41,12 +41,20 @@ | ||
41 | 41 | } |
42 | 42 | }) |
43 | 43 | } |
44 | 44 | |
45 | + /** | |
46 | + * starts the container | |
47 | + * @returns {Promise} | |
48 | + */ | |
45 | 49 | start () { |
46 | 50 | return this.ports.start() |
47 | 51 | } |
48 | 52 | |
53 | + /** | |
54 | + * adds a message to this containers message queue | |
55 | + * @param {Message} message | |
56 | + */ | |
49 | 57 | queue (message) { |
50 | 58 | message._hops++ |
51 | 59 | this.ports.queue(message) |
52 | 60 | if (this.containerState !== 'running') { |
portManager.js | ||
---|---|---|
@@ -105,15 +105,15 @@ | ||
105 | 105 | return portRef |
106 | 106 | } |
107 | 107 | |
108 | 108 | // waits till all ports have reached a threshold tick count |
109 | - wait (threshold, fromPort) { | |
109 | + wait (threshold, fromPort = this.entryPort, ports = this._portMap) { | |
110 | 110 | // find the ports that have a smaller tick count then the threshold tick count |
111 | - const unkownPorts = [...this._portMap].filter(([portRef, port]) => { | |
111 | + const unkownPorts = [...ports].filter(([portRef, port]) => { | |
112 | 112 | return port.ticks < threshold && fromPort !== portRef |
113 | 113 | }) |
114 | 114 | |
115 | - const promises = unkownPorts.map(async ([portRef, port]) => { | |
115 | + const promises = unkownPorts.map(async([portRef, port]) => { | |
116 | 116 | // update the port's tick count |
117 | 117 | port.ticks = await this.hypervisor.wait(portRef, threshold, this.entryPort) |
118 | 118 | }) |
119 | 119 | |
@@ -121,9 +121,9 @@ | ||
121 | 121 | } |
122 | 122 | |
123 | 123 | async getNextMessage () { |
124 | 124 | if (this._portMap.size) { |
125 | - await this.wait(this.exoInterface.ticks, this.entryPort) | |
125 | + await this.wait(this.exoInterface.ticks) | |
126 | 126 | const portMap = [...this._portMap].reduce(messageArbiter) |
127 | 127 | return portMap[1].shift() |
128 | 128 | } |
129 | 129 | } |
Built with git-ssb-web