本文整理匯總了TypeScript中events.EventEmitter類的典型用法代碼示例。如果您正苦於以下問題:TypeScript EventEmitter類的具體用法?TypeScript EventEmitter怎麽用?TypeScript EventEmitter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了EventEmitter類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('.get with invalid service name and arguments', done => {
const socket = new EventEmitter();
provider.emit('connection', socket);
socket.emit('get', null, (error: any) => {
assert.strictEqual(error.name, 'NotFound');
assert.strictEqual(error.message, `Service 'null' not found`);
done();
});
});
示例2: addHandler
function addHandler(emitter: EventEmitter, event: string, handler: (...args: Array<any>) => void) {
if (isLogEvent) {
emitter.on(event, (...args: Array<any>) => {
console.log("%s %s", event, args)
handler.apply(null, args)
})
}
else {
emitter.on(event, handler)
}
}
示例3: test
test('`waitUntilWatchIsReady` correctly handles `tsc` output', async () => {
buildOutputStream.emit('data', Buffer.from('$ tsc'));
buildOutputStream.emit('data', Buffer.from('Compilation complete.'));
jest.runAllTimers();
expect(await completionHintPromise).toBe('tsc');
});
示例4: test
test('`waitUntilWatchIsReady` fallbacks to default output handler if output is not recognizable', async () => {
buildOutputStream.emit('data', Buffer.from('$ some-cli'));
buildOutputStream.emit('data', Buffer.from('Compilation complete.'));
buildOutputStream.emit('data', Buffer.from('Chunk Names.'));
jest.runAllTimers();
expect(await completionHintPromise).toBe('timeout');
});
示例5: return
return () => {
bag.dispose();
if (input) {
input.removeAllListeners();
}
if (output) {
output.removeAllListeners();
}
};
示例6:
window.addEventListener("storage", (event) => {
if (event.key !== storageKey) return;
const oldPub = pub;
pub = JSON.parse(event.newValue);
if (oldPub.keyMap !== pub.keyMap) emitter.emit("keyMap");
if (oldPub.theme !== pub.theme) emitter.emit("theme");
});
示例7: resolve
return new Promise<any>((resolve, reject) => {
emitter.once(event, (value: any) => {
resolve(value);
});
emitter.once('error', (err: Error) => {
reject(err);
});
});
示例8: function
zoneA.run(() => {
emitter.on('removeListener', function(type: string, handler: any) {
zoneResults.push('remove' + type);
});
emitter.on('test', shouldNotRun);
emitter.on('test1', expectZoneA);
emitter.removeAllListeners('test');
expect(zoneResults).toEqual(['removetest']);
expect(emitter.listeners('removeListener').length).toBe(1);
});
示例9: function
response.on('end', function() {
try {
output = JSON.parse(content)
emitter.emit('done', output)
}
catch (e) {
e.cause = content
emitter.emit('error', e)
}
})