Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

after-every

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

after-every

Run a function after every second/minute/hour...

latest
Source
npmnpm
Version
1.0.4
Version published
Maintainers
1
Created
Source

after-every

This package allows you to run a function after a time interval of seconds, minutes, hours or days. The function is created to run after the time in millisecond becomes 0. For example, the seconds will run after the time in milliseconds becomes 0. The minute function will run after the time in seconds becomes 0, and so on.

This is useful for projects that need to run a function as the second or minute changes.

Installation & Importing

npm install after-every

or

yarn add after-every

then import the module like either of the two ways below depending on your project

// Import statements
import AfterEvery from "after-every"

// Require statements
const AfterEvery = require("after-every").default

Usage

To create a timer that runs every 5 minutes, all I have to do is this

AfterEvery(5).minutes(date => {
	console.log("I run every 5 minutes")
}) 

It works the same way for all other time durations

AfterEvery(1).seconds(date => {})
AfterEvery(5).minutes(date => {})
AfterEvery(10).hours(date => {})
AfterEvery(7).days(date => {})

To clear the timeout, just call the function again

const timer = AfterEvery(1).seconds(date => console.log(`A second passed!, now it's ${date.getSeconds()} seconds`))
setTimeout(() => {
	timer()
}, 3000)

// > Output
// A second passed! now it's 1 seconds
// A second passed! now it's 2 seconds
// A second passed! now it's 3 seconds

Fixing AfterEvery().days() with set_timezone()

AfterEvery().days() runs every time UTC hours strikes 0. Since the timezone your run your code in might be different from that of UTC, there is a function for your to set your custom timezone so that AfterEvery().days() runs when your timezone days starts

import { set_timezone } from "after-every"

set_timezone(8)  // For UTC+08:00
set_timezone(-3) // For UTC-03:00

Keywords

time

FAQs

Package last updated on 27 Nov 2021

Did you know?

Socket

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.

Install

Related posts