
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
task-clock
Advanced tools
npm i task-clockconst { TaskClock } = require("task-clock");
options <Object>
start <Date> Default: new Date()
autoStart <boolean> Default: true
false the taskClock does not start untill the method start is invoked.
interval <Object>
d <number> Default: 0
h <number> Default: 0
m <number> Default: 0
s <number> Default: 0
ms <number> Default: 0
2.5 hours is equal to 9 million milliseconds.
ticks <integer> Default: Infinity
Infinity and that is never reached. The largest possible date in JavaScript is in the year 275760 when milliseconds reach 8640000000000000 and this is smaller than Number.MAX_SAFE_INTEGER 9007199254740991.
task <Function>
lastTick <Function>
now <DateModel> Default: <Date>
tick <number>
now <DateModel> Default: <Date>
tick <number>
now <DateModel> Default: <Date>
tick <number>
false in the constructor invoke this method manually.
const LocaleTimezoneDate = require("locale-timezone-date");
const { TaskClock } = require("task-clock");
// ...
//*
new TaskClock({
start: new Date(new Date().setSeconds(0, 0)), interval: { s: 3 }, ticks: 3,
task: (now, tick) => console.log(now.toISOString(), "task", tick)
});
// 2021-04-08T23:31:06.720Z task 1
// 2021-04-08T23:31:09.014Z task 2
// 2021-04-08T23:31:12.003Z task 3
// 2021-04-08T23:31:15.010Z done
// ...
//*/
//*
class MyClockA extends TaskClock {
task(now, tick) {
const nowMs = now.getTime();
const delay = nowMs - this.prevTick;
if (tick > 1)
console.log(now.toLocaleISOString(), `delay: ${delay} ms`);
else
console.log(now.toLocaleISOString());
this.prevTick = this.nextTick;
};
lastTick(now, tick) {
console.log(now.toLocaleISOString(), "last tick", tick);
};
get DateModel() {
return LocaleTimezoneDate;
};
};
new MyClockA({ start: new LocaleTimezoneDate().startOfDate({ ms: false }), interval: { ms: 200 }, ticks: 10 });
// 2021-04-09T01:34:37.736+0200
// 2021-04-09T01:34:37.802+0200 delay: 2 ms
// 2021-04-09T01:34:38.005+0200 delay: 5 ms
// 2021-04-09T01:34:38.206+0200 delay: 6 ms
// 2021-04-09T01:34:38.408+0200 delay: 8 ms
// 2021-04-09T01:34:38.611+0200 delay: 11 ms
// 2021-04-09T01:34:38.815+0200 delay: 15 ms
// 2021-04-09T01:34:39.001+0200 delay: 1 ms
// 2021-04-09T01:34:39.205+0200 delay: 5 ms
// 2021-04-09T01:34:39.407+0200 delay: 7 ms
// 2021-04-09T01:34:39.611+0200 last tick 11
// ...
//*/
//*
class MyClockB extends TaskClock {
#finish;
constructor(finish, lastTick) {
super({
start: new Date(new Date().setHours(0, 0, 0, 0)),
interval: { ms: 200 },
ticks: 10,
lastTick, // if condition did not meet reject on lastTick
autoStart: false // maybe i need to initialize a property
});
this.#finish = finish;
this.start();
};
task(now, tick) {
const nowMs = now.getTime();
const delay = nowMs - this.prevTick;
if (tick > 1)
console.log(now.toLocaleISOString(), `delay: ${delay} ms`, tick);
else
console.log(now.toLocaleISOString());
if (delay <= 2)
return this.stop();
this.prevTick = this.nextTick;
};
stop() {
this.lastTick = this.#finish
super.stop();
};
get DateModel() {
return LocaleTimezoneDate;
};
static promisify(resolve, reject) {
return new MyClockB(resolve, reject);
};
};
new Promise(MyClockB.promisify)
.then(() => console.log("finished promise"))
.catch(now => console.log("Rejected: ", now.toLocaleISOString()));
/*
2022-05-15T14:38:32.816+0200 1
2022-05-15T14:38:33.011+0200 2 delay: 11 ms
2022-05-15T14:38:33.214+0200 3 delay: 14 ms
2022-05-15T14:38:33.404+0200 4 delay: 4 ms
2022-05-15T14:38:33.606+0200 5 delay: 6 ms
2022-05-15T14:38:33.810+0200 6 delay: 10 ms
2022-05-15T14:38:34.015+0200 7 delay: 15 ms
2022-05-15T14:38:34.203+0200 8 delay: 3 ms
2022-05-15T14:38:34.406+0200 9 delay: 6 ms
2022-05-15T14:38:34.610+0200 10 delay: 10 ms
Rejected: 2022-05-15T14:38:34.812+0200
-----
2022-05-15T14:39:51.967+0200 1
2022-05-15T14:39:52.009+0200 2 delay: 9 ms
2022-05-15T14:39:52.212+0200 3 delay: 12 ms
2022-05-15T14:39:52.400+0200 4 delay: 0 ms
finished promise
*/
//*
const timer = new TaskClock();
// 2021-03-07T15:21:15.274Z running task 1
// 2021-03-07T15:21:16.281Z running task 2
// 2021-03-07T15:21:17.283Z running task 3
// etc...
// ...
//{somewhere in the future} running task 1057304576
timer.finish();
//{somewhere in the future} done
//*/
FAQs
Task scheduler
We found that task-clock demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.