| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f45793c commit 6971630
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,12 +32,12 @@ if (cluster.isWorker) { | |||
| 32 | 32 | // start worker | |
| 33 | 33 | var worker = cluster.fork(); | |
| 34 | 34 | ||
| 35 | - var socket; | ||
| 36 | 35 | // Disconnect worker when it is ready | |
| 37 | 36 | worker.once('listening', function() { | |
| 38 | - net.createConnection(common.PORT, common.localhostIPv4, function() { | ||
| 39 | - socket = this; | ||
| 40 | - this.on('data', function() { | ||
| 37 | + const socket = net.createConnection(common.PORT, common.localhostIPv4); | ||
| 38 | + | ||
| 39 | + socket.on('connect', function() { | ||
| 40 | + socket.on('data', function() { | ||
| 41 | 41 | console.log('got data from client'); | |
| 42 | 42 | // socket definitely connected to worker if we got data | |
| 43 | 43 | worker.disconnect(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,9 +50,8 @@ server.listen(0, options.host, function() { | |||
| 50 | 50 | this.destroy(); | |
| 51 | 51 | }); | |
| 52 | 52 | req.setTimeout(50, function() { | |
| 53 | - var req = this; | ||
| 54 | 53 | console.log('req#' + this.id + ' timeout'); | |
| 55 | - req.abort(); | ||
| 54 | + this.abort(); | ||
| 56 | 55 | requests_done += 1; | |
| 57 | 56 | }); | |
| 58 | 57 | req.end(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,26 +21,24 @@ os.homedir = function() { | |||
| 21 | 21 | class ActionStream extends stream.Stream { | |
| 22 | 22 | run(data) { | |
| 23 | 23 | const _iter = data[Symbol.iterator](); | |
| 24 | - const self = this; | ||
| 25 | - | ||
| 26 | - function doAction() { | ||
| 24 | + const doAction = () => { | ||
| 27 | 25 | const next = _iter.next(); | |
| 28 | 26 | if (next.done) { | |
| 29 | 27 | // Close the repl. Note that it must have a clean prompt to do so. | |
| 30 | - setImmediate(function() { | ||
| 31 | - self.emit('keypress', '', { ctrl: true, name: 'd' }); | ||
| 28 | + setImmediate(() => { | ||
| 29 | + this.emit('keypress', '', { ctrl: true, name: 'd' }); | ||
| 32 | 30 | }); | |
| 33 | 31 | return; | |
| 34 | 32 | } | |
| 35 | 33 | const action = next.value; | |
| 36 | 34 | ||
| 37 | 35 | if (typeof action === 'object') { | |
| 38 | - self.emit('keypress', '', action); | ||
| 36 | + this.emit('keypress', '', action); | ||
| 39 | 37 | } else { | |
| 40 | - self.emit('data', action + '\n'); | ||
| 38 | + this.emit('data', action + '\n'); | ||
| 41 | 39 | } | |
| 42 | 40 | setImmediate(doAction); | |
| 43 | - } | ||
| 41 | + }; | ||
| 44 | 42 | setImmediate(doAction); | |
| 45 | 43 | } | |
| 46 | 44 | resume() {} | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -102,24 +102,24 @@ SlowStream.prototype.pause = function() { | |||
| 102 | 102 | }; | |
| 103 | 103 | ||
| 104 | 104 | SlowStream.prototype.resume = function() { | |
| 105 | - var self = this; | ||
| 106 | - if (self.ended) return; | ||
| 107 | - self.emit('resume'); | ||
| 108 | - if (!self.chunk) return; | ||
| 109 | - self.paused = false; | ||
| 110 | - emit(); | ||
| 111 | - function emit() { | ||
| 112 | - if (self.paused) return; | ||
| 113 | - if (self.offset >= self.length) { | ||
| 114 | - self.ended = true; | ||
| 115 | - return self.emit('end'); | ||
| 105 | + const emit = () => { | ||
| 106 | + if (this.paused) return; | ||
| 107 | + if (this.offset >= this.length) { | ||
| 108 | + this.ended = true; | ||
| 109 | + return this.emit('end'); | ||
| 116 | 110 | } | |
| 117 | - var end = Math.min(self.offset + self.trickle, self.length); | ||
| 118 | - var c = self.chunk.slice(self.offset, end); | ||
| 119 | - self.offset += c.length; | ||
| 120 | - self.emit('data', c); | ||
| 111 | + var end = Math.min(this.offset + this.trickle, this.length); | ||
| 112 | + var c = this.chunk.slice(this.offset, end); | ||
| 113 | + this.offset += c.length; | ||
| 114 | + this.emit('data', c); | ||
| 121 | 115 | process.nextTick(emit); | |
| 122 | - } | ||
| 116 | + }; | ||
| 117 | + | ||
| 118 | + if (this.ended) return; | ||
| 119 | + this.emit('resume'); | ||
| 120 | + if (!this.chunk) return; | ||
| 121 | + this.paused = false; | ||
| 122 | + emit(); | ||
| 123 | 123 | }; | |
| 124 | 124 | ||
| 125 | 125 | SlowStream.prototype.end = function(chunk) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments