File size: 771 Bytes
5641073
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const isPromiseLike = (value) => typeof value === 'object' && !!value && 'then' in value;
/**
 * A helper function that calls `.dispose()` on the {@link IDisposable} when
 * the given function (or promise returned by the function) returns.
 */
exports.using = (disposable, fn) => {
    let ret;
    try {
        ret = fn(disposable);
    }
    catch (e) {
        disposable.dispose();
        throw e;
    }
    if (!isPromiseLike(ret)) {
        disposable.dispose();
        return ret;
    }
    return ret.then(value => {
        disposable.dispose();
        return value;
    }, err => {
        disposable.dispose();
        throw err;
    });
};
//# sourceMappingURL=disposable.js.map