@matrixai/contexts
Advanced tools
Comparing version 1.1.0 to 1.2.0
import type { ResourceAcquire } from '@matrixai/resources'; | ||
import type { PromiseCancellableController } from '@matrixai/async-cancellable'; | ||
import type { RWLockReader, RWLockWriter, LockBox } from '@matrixai/async-locks'; | ||
import { Timer } from '@matrixai/timer'; | ||
import { Monitor } from '@matrixai/async-locks'; | ||
declare const AsyncFunction: Function; | ||
@@ -21,2 +23,5 @@ declare const GeneratorFunction: Function; | ||
}, delay?: number, lazy?: boolean, controller?: PromiseCancellableController): ResourceAcquire<Timer<T>>; | ||
declare function monitor<RWLock extends RWLockReader | RWLockWriter>(lockBox: LockBox<RWLock>, lockConstructor: new () => RWLock, locksPending?: Map<string, { | ||
count: number; | ||
}>): ResourceAcquire<Monitor<RWLock>>; | ||
declare function isPromiseLike(v: any): v is PromiseLike<unknown>; | ||
@@ -33,2 +38,2 @@ /** | ||
declare function isAsyncGenerator(v: any): v is AsyncGenerator<unknown>; | ||
export { AsyncFunction, GeneratorFunction, AsyncGeneratorFunction, contexts, getContextIndex, checkContextCancellable, checkContextTimed, timer, isPromiseLike, isGenerator, isAsyncGenerator, }; | ||
export { AsyncFunction, GeneratorFunction, AsyncGeneratorFunction, contexts, getContextIndex, checkContextCancellable, checkContextTimed, timer, monitor, isPromiseLike, isGenerator, isAsyncGenerator, }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isAsyncGenerator = exports.isGenerator = exports.isPromiseLike = exports.timer = exports.checkContextTimed = exports.checkContextCancellable = exports.getContextIndex = exports.contexts = exports.AsyncGeneratorFunction = exports.GeneratorFunction = exports.AsyncFunction = void 0; | ||
exports.isAsyncGenerator = exports.isGenerator = exports.isPromiseLike = exports.monitor = exports.timer = exports.checkContextTimed = exports.checkContextCancellable = exports.getContextIndex = exports.contexts = exports.AsyncGeneratorFunction = exports.GeneratorFunction = exports.AsyncFunction = void 0; | ||
const timer_1 = require("@matrixai/timer"); | ||
const async_locks_1 = require("@matrixai/async-locks"); | ||
const AsyncFunction = (async () => { }).constructor; | ||
@@ -65,2 +66,14 @@ exports.AsyncFunction = AsyncFunction; | ||
exports.timer = timer; | ||
function monitor(lockBox, lockConstructor, locksPending) { | ||
return async () => { | ||
const monitor = new async_locks_1.Monitor(lockBox, lockConstructor, locksPending); | ||
return [ | ||
async () => { | ||
await monitor.unlockAll(); | ||
}, | ||
monitor, | ||
]; | ||
}; | ||
} | ||
exports.monitor = monitor; | ||
function isPromiseLike(v) { | ||
@@ -67,0 +80,0 @@ return v != null && typeof v.then === 'function'; |
{ | ||
"name": "@matrixai/contexts", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"author": "Roger Qiu", | ||
@@ -5,0 +5,0 @@ "description": "Asynchronous contexts", |
Sorry, the diff of this file is not supported yet
85385
1066