| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3605726 commit b0cb787
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 2 | + const common = require('../common'); | ||
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | const stream = require('stream'); | |
| 5 | 5 | const str = 'asdfasdfasdfasdfasdf'; | |
@@ -10,29 +10,25 @@ const r = new stream.Readable({ | |||
| 10 | 10 | }); | |
| 11 | 11 | ||
| 12 | 12 | let reads = 0; | |
| 13 | - let eofed = false; | ||
| 14 | - let ended = false; | ||
| 15 | 13 | ||
| 16 | - r._read = function(n) { | ||
| 14 | + function _read() { | ||
| 17 | 15 | if (reads === 0) { | |
| 18 | 16 | setTimeout(function() { | |
| 19 | 17 | r.push(str); | |
| 20 | - }); | ||
| 18 | + }, 1); | ||
| 21 | 19 | reads++; | |
| 22 | 20 | } else if (reads === 1) { | |
| 23 | 21 | var ret = r.push(str); | |
| 24 | 22 | assert.strictEqual(ret, false); | |
| 25 | 23 | reads++; | |
| 26 | 24 | } else { | |
| 27 | - assert(!eofed); | ||
| 28 | - eofed = true; | ||
| 29 | 25 | r.push(null); | |
| 30 | 26 | } | |
| 31 | - }; | ||
| 27 | + } | ||
| 32 | 28 | ||
| 33 | - r.on('end', function() { | ||
| 34 | - ended = true; | ||
| 35 | - }); | ||
| 29 | + r._read = common.mustCall(_read, 3); | ||
| 30 | + | ||
| 31 | + r.on('end', common.mustCall(function() {})); | ||
| 36 | 32 | ||
| 37 | 33 | // push some data in to start. | |
| 38 | 34 | // we've never gotten any read event at this point. | |
@@ -55,10 +51,3 @@ r.once('readable', function() { | |||
| 55 | 51 | chunk = r.read(); | |
| 56 | 52 | assert.strictEqual(chunk, null); | |
| 57 | 53 | }); | |
| 58 | - | ||
| 59 | - process.on('exit', function() { | ||
| 60 | - assert(eofed); | ||
| 61 | - assert(ended); | ||
| 62 | - assert.strictEqual(reads, 2); | ||
| 63 | - console.log('ok'); | ||
| 64 | - }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments