mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-05 17:23:51 -05:00
SQL Operations Studio Public Preview 1 (0.23) release source code
This commit is contained in:
29
src/vs/base/common/cache.ts
Normal file
29
src/vs/base/common/cache.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
|
||||
export default class Cache<T> {
|
||||
|
||||
private promise: TPromise<T> = null;
|
||||
constructor(private task: () => TPromise<T>) { }
|
||||
|
||||
get(): TPromise<T> {
|
||||
if (this.promise) {
|
||||
return this.promise;
|
||||
}
|
||||
|
||||
const promise = this.task();
|
||||
|
||||
this.promise = new TPromise<T>((c, e) => promise.done(c, e), () => {
|
||||
this.promise = null;
|
||||
promise.cancel();
|
||||
});
|
||||
|
||||
return this.promise;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user