Skip to content

Commit

Permalink
add typings to support Promise#finally
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Dec 14, 2018
1 parent ece3a90 commit 45e4793
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/typings/lib.es2018.promise.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http:https://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */

/**
* Represents the completion of an asynchronous operation
*/
interface Promise<T> {
/**
* Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
* resolved value cannot be modified from the callback.
* @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
* @returns A Promise for the completion of the callback.
*/
finally(onfinally?: (() => void) | undefined | null): Promise<T>;
}
3 changes: 3 additions & 0 deletions src/vs/base/common/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export function createCancelablePromise<T>(callback: (token: CancellationToken)
catch<TResult = never>(reject?: ((reason: any) => TResult | Promise<TResult>) | undefined | null): Promise<T | TResult> {
return this.then(undefined, reject);
}
finally(onfinally?: (() => void) | undefined | null): Promise<T> {
return this.finally(onfinally);
}
};
}

Expand Down
3 changes: 3 additions & 0 deletions src/vs/workbench/api/node/extHostSearch.fileIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,9 @@ export class FileIndexSearchManager {
catch(reject?) {
return this.then(undefined, reject);
}
finally(onFinally) {
return promise.finally(onFinally);
}
};
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/vs/workbench/services/extensions/node/lazyPromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,8 @@ export class LazyPromise implements Promise<any> {
public catch(error: any): any {
return this._ensureActual().then(undefined, error);
}

public finally(callback): any {
return this._ensureActual().finally(callback);
}
}
3 changes: 3 additions & 0 deletions src/vs/workbench/services/search/node/rawSearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ export class SearchService implements IRawSearchService {
catch(reject?) {
return this.then(undefined, reject);
}
finally(onFinally) {
return promise.finally(onFinally);
}
};
}
}
Expand Down

0 comments on commit 45e4793

Please sign in to comment.