| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c1aee02 commit 0216dbe
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - const common = require('../common'); | ||
| 2 | + require('../common'); | ||
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | ||
| 5 | 5 | const Readable = require('stream').Readable; | |
@@ -16,36 +16,35 @@ function test1() { | |||
| 16 | 16 | // | |
| 17 | 17 | // note that this is very unusual. it only works for crypto streams | |
| 18 | 18 | // because the other side of the stream will call read(0) to cycle | |
| 19 | - // data through openssl. that's why we set the timeouts to call | ||
| 19 | + // data through openssl. that's why setImmediate() is used to call | ||
| 20 | 20 | // r.read(0) again later, otherwise there is no more work being done | |
| 21 | 21 | // and the process just exits. | |
| 22 | 22 | ||
| 23 | 23 | const buf = Buffer.alloc(5, 'x'); | |
| 24 | 24 | let reads = 5; | |
| 25 | - const timeout = common.platformTimeout(50); | ||
| 26 | 25 | r._read = function(n) { | |
| 27 | 26 | switch (reads--) { | |
| 28 | - case 0: | ||
| 29 | - return r.push(null); // EOF | ||
| 30 | - case 1: | ||
| 31 | - return r.push(buf); | ||
| 32 | - case 2: | ||
| 33 | - setTimeout(r.read.bind(r, 0), timeout); | ||
| 34 | - return r.push(Buffer.alloc(0)); // Not-EOF! | ||
| 35 | - case 3: | ||
| 36 | - setTimeout(r.read.bind(r, 0), timeout); | ||
| 37 | - return process.nextTick(function() { | ||
| 38 | - return r.push(Buffer.alloc(0)); | ||
| 27 | + case 5: | ||
| 28 | + return setImmediate(function() { | ||
| 29 | + return r.push(buf); | ||
| 39 | 30 | }); | |
| 40 | 31 | case 4: | |
| 41 | - setTimeout(r.read.bind(r, 0), timeout); | ||
| 42 | - return setTimeout(function() { | ||
| 32 | + setImmediate(function() { | ||
| 43 | 33 | return r.push(Buffer.alloc(0)); | |
| 44 | 34 | }); | |
| 45 | - case 5: | ||
| 46 | - return setTimeout(function() { | ||
| 47 | - return r.push(buf); | ||
| 35 | + return setImmediate(r.read.bind(r, 0)); | ||
| 36 | + case 3: | ||
| 37 | + setImmediate(r.read.bind(r, 0)); | ||
| 38 | + return process.nextTick(function() { | ||
| 39 | + return r.push(Buffer.alloc(0)); | ||
| 48 | 40 | }); | |
| 41 | + case 2: | ||
| 42 | + setImmediate(r.read.bind(r, 0)); | ||
| 43 | + return r.push(Buffer.alloc(0)); // Not-EOF! | ||
| 44 | + case 1: | ||
| 45 | + return r.push(buf); | ||
| 46 | + case 0: | ||
| 47 | + return r.push(null); // EOF | ||
| 49 | 48 | default: | |
| 50 | 49 | throw new Error('unreachable'); | |
| 51 | 50 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments