https://github.com/dresende/chron
NodeJS task scheduler
https://github.com/dresende/chron
Last synced: 5 months ago
JSON representation
NodeJS task scheduler
- Host: GitHub
- URL: https://github.com/dresende/chron
- Owner: dresende
- License: mit
- Created: 2015-06-21T18:23:49.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-01-17T10:16:34.000Z (almost 8 years ago)
- Last Synced: 2025-08-09T03:15:06.973Z (5 months ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Chron
NodeJS task scheduler.
## Install
```sh
npm install chron
```
## Usage
```js
var chron = new require("chron")();
chron.add(10, doSomething); // called every 10 seconds
chron.add(1.5, doSomething); // called every 1.5 seconds
function doSomething() {
console.log("doing..");
}
```
The advantage of the scheduler is it only has one timer, even if you have hundreds of tasks. It calculates when the next task needs to run and schedules a timer.
## API
- chron.add(period, task)
- chron.remove(task)
- chron.clear()
- chron.pause()
- chron.resume()
A `task` is a function that receives a parameter that you can use to control the task execution (the next calls).
```js
function doSomething($) {
$.pause(); // will stop executing, you need to store
// a reference to $ to be able to resume
$.resume(); // resume the previsouly paused task
$.remove(); // completely remove the task - equal to chron.remove(task)
}
```