How to use the @esfx/disposable.Disposable.dispose function in @esfx/disposable

To help you get started, we’ve selected a few @esfx/disposable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github esfx / esfx / packages / async-mutex / src / index.ts View on Github external
[AsyncLockable.unlock]() {
        this.unlock();
    }
    // #endregion AsyncLockable
}

const disposablePrototype: object = Object.getPrototypeOf(Disposable.create(() => {}));

const mutexLockHandlePrototype: object = {
    [AsyncLockable.lock](this: LockHandle, cancelable?: Cancelable) {
        return this.lock(cancelable);
    },
    [AsyncLockable.unlock](this: LockHandle) {
        return this.unlock();
    },
    [Disposable.dispose](this: LockHandle) {
        if (this.ownsLock) {
            this.unlock();
        }
    }
};

defineTag(mutexLockHandlePrototype, "MutexLockHandle");
Object.setPrototypeOf(mutexLockHandlePrototype, disposablePrototype);

function createLockHandle(mutex: AsyncMutex): LockHandle {
    const handle: LockHandle = Object.setPrototypeOf({
        get mutex() {
            return mutex;
        },
        get ownsLock() {
            return mutex["_handle"] === handle;
github esfx / esfx / packages / cancelable / src / index.ts View on Github external
Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

import { Disposable } from "@esfx/disposable";
import { isFunction, isMissing, isObject } from "@esfx/internal-guards";
import { defineTag } from "@esfx/internal-tag";
import { deprecateProperty } from "@esfx/internal-deprecate";

const disposablePrototype = Object.getPrototypeOf(Disposable.create(() => {}));

const cancelSubscriptionPrototype: Disposable = defineTag(Object.setPrototypeOf({
    [Disposable.dispose](this: CancelSubscription) {
        this.unsubscribe();
    },
}, disposablePrototype), "CancelSubscription");

function createCancelSubscription(unsubscribe: () => void): CancelSubscription {
    return Object.setPrototypeOf({
        unsubscribe() {
            unsubscribe();
        },
    }, cancelSubscriptionPrototype);
}

/**
 * An object that can be canceled from an external source.
 */
export interface Cancelable {
github esfx / esfx / packages / async-readerwriterlock / src / index.ts View on Github external
export { LockHandle, UpgradeableLockHandle } from "@esfx/async-lockable";

const disposablePrototype: object = Object.getPrototypeOf(Disposable.create(() => { }));

const lockHandlePrototype: object = {
    get mutex() {
        return this;
    },
    async [AsyncLockable.lock](this: LockHandle, cancelable?: Cancelable) {
        await this.lock(cancelable);
        return this;
    },
    [AsyncLockable.unlock](this: LockHandle) {
        this.unlock();
    },
    [Disposable.dispose](this: LockHandle) {
        if (this.ownsLock) {
            this.unlock();
        }
    }
};

defineTag(lockHandlePrototype, "LockHandle");
Object.setPrototypeOf(lockHandlePrototype, disposablePrototype);

const readerPrototype: object = {};
defineTag(readerPrototype, "AsyncReaderWriterLockReader");
Object.setPrototypeOf(readerPrototype, lockHandlePrototype);

const writerPrototype: object = {};
defineTag(writerPrototype, "AsyncReaderWriterLockWriter");
Object.setPrototypeOf(writerPrototype, lockHandlePrototype);

@esfx/disposable

A low-level API for defining explicit resource management.

Apache-2.0
Latest version published 2 years ago

Package Health Score

51 / 100
Full package analysis

Similar packages