Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
CMCDragonkai committed Jun 28, 2023
1 parent 7e2bc07 commit 16c1549
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Empty file added src/decorators/monitored.ts
Empty file.
28 changes: 28 additions & 0 deletions src/functions/monitored.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

// IF you have a `@monitored`
// That means you have `@timedCancellable` at thes ame time
// You can do `@timed` `@cancellable`
// But instead `@timedCancellable` combines them all
// SO @monitored does it too
// Cause if you can lock things... you can also use the timer and monitor
// Due to the usageo f the locking ctx
// await ctx.monitor.lock(...)
// someotherfunction(ctx)
// it passes the monitor down there
// Well the problem is that whe nyou do it
// you'd need to have the timer monitor applied?
// you don'tn eed to apply the ctx
// the ctx is automtaically applied( so the function ctx of timer and signal)
// isautomatically applied to all LOCKS
// when you do this you also need to use the ability to create a monitor
// obj.withMonitor(async (monitor) => {
// })

// I wnat to see to quickly prototyep what this will look like


function monitored() {

}

export default monitored;
26 changes: 26 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ResourceAcquire } from '@matrixai/resources';
import type { PromiseCancellableController } from '@matrixai/async-cancellable';
import { Timer } from '@matrixai/timer';
import { Monitor, LockBox, RWLockReader, RWLockWriter } from '@matrixai/async-locks';

const AsyncFunction = (async () => {}).constructor;
const GeneratorFunction = function* () {}.constructor;
Expand Down Expand Up @@ -97,6 +98,30 @@ function timer<T = void>(
};
}

/**
* Monitor resource.
* Use it with `withF` or `withG`.
*/
function monitor<RWLock extends RWLockReader | RWLockWriter>(
lockBox: LockBox<RWLock>,
lockConstructor: new () => RWLock,
locksPending?: Map<string, { count: number }>,
): ResourceAcquire<Monitor<RWLock>> {
return async () => {
const monitor = new Monitor<RWLock>(
lockBox,
lockConstructor,
locksPending
);
return [
async () => {
await monitor.unlockAll();
},
monitor
];
};
}

function isPromiseLike(v: any): v is PromiseLike<unknown> {
return v != null && typeof v.then === 'function';
}
Expand Down Expand Up @@ -139,6 +164,7 @@ export {
checkContextCancellable,
checkContextTimed,
timer,
monitor,
isPromiseLike,
isGenerator,
isAsyncGenerator,
Expand Down

0 comments on commit 16c1549

Please sign in to comment.