(options)
| 8 | const EndpointManager = dependencies.EndpointManager; |
| 9 | |
| 10 | function Client (options) { |
| 11 | this.config = config(options); |
| 12 | |
| 13 | this.endpointManager = new EndpointManager(this.config); |
| 14 | this.endpointManager.on("wakeup", () => { |
| 15 | while (this.queue.length > 0) { |
| 16 | const stream = this.endpointManager.getStream(); |
| 17 | if (!stream) { |
| 18 | return; |
| 19 | } |
| 20 | const resolve = this.queue.shift(); |
| 21 | resolve(stream); |
| 22 | } |
| 23 | |
| 24 | if (this.shutdownPending) { |
| 25 | this.endpointManager.shutdown(); |
| 26 | } |
| 27 | }); |
| 28 | |
| 29 | this.endpointManager.on("error", (err) => { |
| 30 | this.queue.forEach((resolve) => { |
| 31 | resolve(Promise.reject(err)); |
| 32 | }); |
| 33 | |
| 34 | this.queue = []; |
| 35 | }); |
| 36 | |
| 37 | this.queue = []; |
| 38 | } |
| 39 | |
| 40 | Client.prototype.write = function write (notification, device, count) { |
| 41 | return this.getStream().then( stream => { |
nothing calls this directly
no test coverage detected
searching dependent graphs…