@jayarjo/scheduler
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "@jayarjo/scheduler", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Schedule a task to execute after some period, regularly with a given interval, just given amount of times, or simply until it succeeds.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -1,1 +0,16 @@ | ||
# taskscheduler | ||
# scheduler | ||
```js | ||
import { scheduler } from '@jayarjo/scheduler' | ||
// run once in certain amount of time units (milliseconds by default) | ||
scheduler.runIn(fn, 5000) // invoke fn in 5 secs | ||
// run consequently with the specified interval | ||
const taskId = scheduler.runEvery(fn, 1000) // invoke every second | ||
// task can be removed if required after certain amount of time | ||
setTimeout(() => { | ||
scheduler.removeTask(taskId) | ||
}, 5000) | ||
``` |
@@ -54,2 +54,13 @@ import { TimeUnits } from './Task' | ||
test('runEvery()', done => { | ||
const spy = jest.fn(() => Promise.resolve('success')) | ||
scheduler.runEvery(spy, 1000) | ||
setTimeout(() => { | ||
expect(spy).toHaveBeenCalledTimes(3) | ||
done() | ||
}, 3000) | ||
}) | ||
test('addTask(schema)', done => { | ||
@@ -56,0 +67,0 @@ const spy = jest.fn().mockResolvedValue('success') |
@@ -66,11 +66,10 @@ import { random } from './Utils' | ||
fn: Function, | ||
amount: number, | ||
interval: number, | ||
unit?: TimeUnits, | ||
repeatTimesBeforeFail? | ||
): string { | ||
const at = Date.now() + (unit ? amount * unit : amount) | ||
return this.addTask( | ||
new Task({ | ||
fn, | ||
at, | ||
interval: unit ? interval * unit : interval, | ||
repeatTimesBeforeFail | ||
@@ -77,0 +76,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17
16581
16
537