本文整理匯總了TypeScript中stream.Readable.emit方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Readable.emit方法的具體用法?TypeScript Readable.emit怎麽用?TypeScript Readable.emit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類stream.Readable
的用法示例。
在下文中一共展示了Readable.emit方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: setImmediate
setImmediate(() => {
let found = false;
for (const mock of MOCKED_FILES) {
if (mock.filename === filename) {
found = true;
rs.emit('error', new Error(mock.error));
break;
}
}
assert.ok(
found,
`The file ${filename} should not be read ` +
`because it doesn't have a mock`
);
});
示例2: function
t.test("handler registered in context on Readable", function (t) {
var Readable = require('stream').Readable;
if (Readable) {
t.plan(12);
var n = cls.createNamespace('outOnReadable')
, re = new Readable()
;
re._read = function () {};
t.ok(n.name, "namespace has a name");
t.equal(n.name, 'outOnReadable', "namespace has a name");
n.run(function () {
n.set('value', 'hello');
n.bindEmitter(re);
t.ok(re.emit.__wrapped, "emit is wrapped");
t.ok(re.on.__wrapped, "on is wrapped");
t.ok(re.addListener.__wrapped, "addListener is wrapped");
re.on('data', function (data: any) {
t.equal(n.get('value'), 'hello', "value still set in EE");
t.equal(data, 'blah', "emit still works");
cls.destroyNamespace('outOnReadable');
});
});
t.ok(re.emit.__wrapped, "emit is still wrapped");
t.ok(re.on.__wrapped, "on is still wrapped");
t.ok(re.addListener.__wrapped, "addListener is still wrapped");
t.equal(typeof re._events.data, 'function', 'only the one data listener');
t.ok(re._events.data['cls@contexts']['context@outOnReadable'],
"context is bound to listener");
re.emit('data', 'blah');
}
else {
t.comment("this test requires node 0.10+");
t.end();
}
});
示例3:
.catch((err: Error) => {
stream.emit('error', err); // Pass on any errors
});
示例4: function
q.on('error', function(err: any) {
stream.emit('error', err); // Pass on any errors
});
示例5: Error
process.nextTick(() => {
const err = new Error(SourceError[402]);
err.stack = option.path;
reader.emit("error", err, option);
reader.destroy();
});