forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisc.ts
More file actions
23 lines (20 loc) · 667 Bytes
/
misc.ts
File metadata and controls
23 lines (20 loc) · 667 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { IAsyncDisposable, IDisposable } from '../types';
// tslint:disable-next-line:no-empty
export function noop() { }
export function using<T extends IDisposable>(disposable: T, func: (obj: T) => void) {
try {
func(disposable);
} finally {
disposable.dispose();
}
}
export async function usingAsync<T extends IAsyncDisposable, R>(disposable: T, func: (obj: T) => Promise<R>) : Promise<R> {
try {
return await func(disposable);
} finally {
await disposable.dispose();
}
}