node/test/parallel/test-stream-writable-write-cb-twice.js
Robert Nagy 4bec6d13f9
stream: enable autoDestroy by default
PR-URL: https://github.com/nodejs/node/pull/30623
Refs: https://github.com/nodejs/node/issues/30621
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2020-01-03 01:49:10 +01:00

53 lines
1003 B
JavaScript

'use strict';
const common = require('../common');
const { Writable } = require('stream');
{
// Sync + Sync
const writable = new Writable({
write: common.mustCall((buf, enc, cb) => {
cb();
cb();
})
});
writable.write('hi');
writable.on('error', common.expectsError({
code: 'ERR_MULTIPLE_CALLBACK',
name: 'Error'
}));
}
{
// Sync + Async
const writable = new Writable({
write: common.mustCall((buf, enc, cb) => {
cb();
process.nextTick(() => {
cb();
});
})
});
writable.write('hi');
writable.on('error', common.expectsError({
code: 'ERR_MULTIPLE_CALLBACK',
name: 'Error'
}));
}
{
// Async + Async
const writable = new Writable({
write: common.mustCall((buf, enc, cb) => {
process.nextTick(cb);
process.nextTick(() => {
cb();
});
})
});
writable.write('hi');
writable.on('error', common.expectsError({
code: 'ERR_MULTIPLE_CALLBACK',
name: 'Error'
}));
}