提交 bbb888f9 编写于 作者: J Joao Moreno

event.once should beware of sync fires

上级 be5a1713
......@@ -305,19 +305,22 @@ export function toNativePromise<T>(event: Event<T>): Thenable<T> {
export function once<T>(event: Event<T>): Event<T> {
return (listener, thisArgs = null, disposables?) => {
let sync = false;
// we need this, in case the event fires during the listener call
let didFire = false;
const result = event(e => {
if (result) {
if (didFire) {
return;
} else if (result) {
result.dispose();
} else {
sync = true;
didFire = true;
}
return listener.call(thisArgs, e);
}, null, disposables);
if (sync) {
if (didFire) {
result.dispose();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册