本文整理汇总了TypeScript中@angular/platform-webworker/src/web_workers/shared/message_bus.MessageBus.to方法的典型用法代码示例。如果您正苦于以下问题:TypeScript MessageBus.to方法的具体用法?TypeScript MessageBus.to怎么用?TypeScript MessageBus.to使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/platform-webworker/src/web_workers/shared/message_bus.MessageBus
的用法示例。
在下文中一共展示了MessageBus.to方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: inject
inject([AsyncTestCompleter, NgZone], (async: AsyncTestCompleter, zone: MockNgZone) => {
bus = createConnectedMessageBus();
setup(false, zone);
let wasCalled = false;
bus.from(CHANNEL).subscribe({next: (message: any) => { wasCalled = true; }});
bus.to(CHANNEL).emit('hi');
flushMessages(() => {
expect(wasCalled).toBeTruthy();
async.done();
});
}), 10000);
示例2: createConnectedMessageBus
(async: AsyncTestCompleter, zone: MockNgZone) => {
bus = createConnectedMessageBus();
setup(true, zone);
var wasCalled = false;
bus.from(CHANNEL).subscribe({next: (message: any) => { wasCalled = true; }});
bus.to(CHANNEL).emit('hi');
flushMessages(() => {
expect(wasCalled).toBeFalsy();
zone.simulateZoneExit();
flushMessages(() => {
expect(wasCalled).toBeTruthy();
async.done();
});
});
}),
示例3: it
it('should broadcast', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const CHANNEL = 'CHANNEL 1';
const MESSAGE = 'TESTING';
const NUM_LISTENERS = 2;
bus.initChannel(CHANNEL, false);
let callCount = 0;
const emitHandler = (message: any) => {
expect(message).toEqual(MESSAGE);
callCount++;
if (callCount == NUM_LISTENERS) {
async.done();
}
};
for (let i = 0; i < NUM_LISTENERS; i++) {
const emitter = bus.from(CHANNEL);
emitter.subscribe({next: emitHandler});
}
const toEmitter = bus.to(CHANNEL);
toEmitter.emit(MESSAGE);
}));