提交 4b7e7891 编写于 作者: J Johannes Rieken

AsyncEmitter shouldn't fail when listener fails

上级 ea89eb90
......@@ -688,7 +688,7 @@ export class AsyncEmitter<T extends IWaitUntil> extends Emitter<T> {
// freeze thenables-collection to enforce sync-calls to
// wait until and then wait for all thenables to resolve
Object.freeze(thenables);
await Promise.all(thenables);
await Promise.all(thenables).catch(e => onUnexpectedError(e));
}
}
}
......
......@@ -350,6 +350,42 @@ suite('AsyncEmitter', function () {
}));
assert.ok(done);
});
test('catch errors', async function () {
const origErrorHandler = Errors.errorHandler.getUnexpectedErrorHandler();
Errors.setUnexpectedErrorHandler(() => null);
interface E extends IWaitUntil {
foo: boolean;
}
let globalState = 0;
let emitter = new AsyncEmitter<E>();
emitter.event(e => {
globalState += 1;
e.waitUntil(new Promise((_r, reject) => reject(new Error())));
});
emitter.event(e => {
globalState += 1;
e.waitUntil(timeout(10));
});
await emitter.fireAsync(thenables => ({
foo: true,
waitUntil(t) {
thenables.push(t);
}
})).then(() => {
assert.equal(globalState, 2);
}).catch(e => {
console.log(e);
assert.ok(false);
});
Errors.setUnexpectedErrorHandler(origErrorHandler);
});
});
suite('PausableEmitter', function () {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册