Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@weedzcokie/scheduler

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@weedzcokie/scheduler - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

22

main.js
/**
* export @typedef Task
* @prop {number} name
* @prop {number} period
* @prop {() => unknown | Promise<unknown>} fn
* @prop {number} timeout
* @prop {() => number} getNextExecutionTime
*/

@@ -12,2 +12,8 @@

export function msUntilFullMinute() {
const date = new Date(Date.now() + 60000);
date.setUTCSeconds(0, 0);
return date.getTime() - Date.now();
}
export function msUntilFullHour() {

@@ -30,8 +36,6 @@ const date = new Date(Date.now() + msInHour);

async function runTask(task) {
const start = Date.now();
await task.fn();
const timeDrift = Date.now() - start;
// Make sure we don't restart a stopped task
if (task.timeout) {
task.timeout = setTimeout(() => runTask(task), task.period - timeDrift);
task.timeout = setTimeout(() => runTask(task), task.getNextExecutionTime());
}

@@ -46,13 +50,13 @@ }

* @param {Task["fn"]} fn
* @param {number} period
* @param {number} [offset=0]
* @param {() => number} [period=() => 1000]
*/
export function schedule(name, fn, period, offset = 0) {
export function schedule(name, fn, period = () => 1000) {
/** @type {Task} */
const task = {
name,
fn,
period,
timeout: 0,
getNextExecutionTime: period,
};
task.timeout = setTimeout(() => runTask(task), task.period + offset);
task.timeout = setTimeout(() => runTask(task), task.getNextExecutionTime());
tasks.set(name, task);

@@ -59,0 +63,0 @@ }

{
"name": "@weedzcokie/scheduler",
"version": "1.0.2",
"version": "1.0.3",
"description": "",

@@ -5,0 +5,0 @@ "type": "module",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc