simplify AsyncEmitter usage

This commit is contained in:
Johannes Rieken
2019-11-19 12:11:12 +01:00
parent 3f69d88abd
commit 839719d489
5 changed files with 43 additions and 78 deletions

View File

@@ -196,26 +196,14 @@ export class ExtHostFileSystemEventService implements ExtHostFileSystemEventServ
private async _fireWillEvent<E extends IWaitUntil>(emitter: AsyncEmitter<E>, data: Omit<E, 'waitUntil'>, token: CancellationToken): Promise<any> {
const edits: WorkspaceEdit[] = [];
await Promise.resolve(emitter.fireAsync(bucket => {
return <E>{
...data,
...{
waitUntil: (thenable: Promise<vscode.WorkspaceEdit>): void => {
if (Object.isFrozen(bucket)) {
throw new TypeError('waitUntil cannot be called async');
}
const promise = Promise.resolve(thenable).then(result => {
// ignore all results except for WorkspaceEdits. Those
// are stored in a spare array
if (result instanceof WorkspaceEdit) {
edits.push(result);
}
});
bucket.push(promise);
}
}
};
}, token));
await emitter.fireAsync(data, token, async p => {
// ignore all results except for WorkspaceEdits. Those are stored in an array.
const result = await Promise.resolve(p);
if (result instanceof WorkspaceEdit) {
edits.push(result);
}
});
if (token.isCancellationRequested) {
return;