This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const chai = require('chai') | |
| const expect = chai.expect | |
| const hello = new require('stream').Writable({ | |
| autoDestroy: true, | |
| destroy (err, callback) { | |
| console.log('6 before callback in _destroy') | |
| process.nextTick(() => console.log('i. before _destory callback nextTick')) | |
| callback(err) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const hello = new require('stream').Writable({ | |
| destroy (err, callback) { | |
| console.log('2 before callback in _destroy') | |
| callback(err) | |
| console.log('3 after callback in _destory') | |
| } | |
| }).on('error', err => console.log('6 error')) | |
| .on('close', () => console.log('7 close')) | |
| console.log('1 before destroy') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // licensed under public domain | |
| // author: matianfu@gmail.com | |
| const EventEmitter = require('events') | |
| // K combinator, not necessary, just for fun | |
| const K = x => y => x | |
| // this class is mainly for settle logic. | |
| // the concrete class should emit a 'finish' event with err/data at the end of the process |