nodejs/test/parallel/test-stream-writable-write-cb-twice.js

50 lines
967 B
JavaScript
Raw Normal View History

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