@danieldiekmeier/async-worker
Advanced tools
Comparing version 1.0.0 to 2.0.0
{ | ||
"name": "@danieldiekmeier/async-worker", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "A simple worker to do work in intervals", | ||
"main": "index.js", | ||
"module": "main.js", | ||
"main": "worker.js", | ||
"type": "module", | ||
"scripts": { | ||
"test": "ava", | ||
"test:watch": "ava --watch --verbose" | ||
"test": "node --test", | ||
"test:watch": "node --test --watch tests" | ||
}, | ||
@@ -17,3 +17,6 @@ "repository": { | ||
"async", | ||
"worker" | ||
"worker", | ||
"interval", | ||
"async-await", | ||
"async-await-worker" | ||
], | ||
@@ -25,19 +28,3 @@ "author": "Daniel Diekmeier", | ||
}, | ||
"homepage": "https://github.com/danieldiekmeier/async-worker#readme", | ||
"dependencies": { | ||
"esm": "^3.2.5" | ||
}, | ||
"ava": { | ||
"files": [ | ||
"tests/*.test.js" | ||
], | ||
"failFast": true, | ||
"compileEnhancements": false, | ||
"require": [ | ||
"esm" | ||
] | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.2.1" | ||
} | ||
"homepage": "https://github.com/danieldiekmeier/async-worker#readme" | ||
} |
# Async Worker | ||
``` | ||
```sh | ||
npm i @danieldiekmeier/async-worker | ||
@@ -18,3 +18,3 @@ ``` | ||
``` | ||
```js | ||
import Worker from '@danieldiekmeier/async-worker' | ||
@@ -21,0 +21,0 @@ |
@@ -1,6 +0,7 @@ | ||
import test from 'ava' | ||
import Worker from '../index.js' | ||
import { test } from 'node:test' | ||
import { strict as assert } from 'node:assert' | ||
import Worker from '../worker.js' | ||
async function wait (duration) { | ||
return new Promise(resolve => { | ||
async function wait(duration) { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, duration) | ||
@@ -10,8 +11,10 @@ }) | ||
test('Worker works', async t => { | ||
test('Worker works', async () => { | ||
let a = 0 | ||
const worker = new Worker({ | ||
async task () { a += 1 }, | ||
interval: 10 | ||
async task() { | ||
a += 1 | ||
}, | ||
interval: 10, | ||
}) | ||
@@ -22,3 +25,3 @@ | ||
// make sure it ran at least twice. | ||
t.true(a >= 2) | ||
assert(a >= 2) | ||
@@ -28,11 +31,11 @@ worker.stop() | ||
test('Worker doesnt start another round if previous round is unfinished', async t => { | ||
test('Worker doesnt start another round if previous round is unfinished', async () => { | ||
let a = 0 | ||
const worker = new Worker({ | ||
async task () { | ||
async task() { | ||
a += 1 | ||
await wait(1000) | ||
await wait(500) | ||
}, | ||
interval: 10 | ||
interval: 10, | ||
}) | ||
@@ -43,3 +46,3 @@ | ||
// ensure that task ran exactly once | ||
t.is(a, 1) | ||
assert(a === 1) | ||
@@ -49,3 +52,3 @@ worker.stop() | ||
test('Worker doesnt crash if task errors', async t => { | ||
test('Worker doesnt crash if task errors', async () => { | ||
let a = 0 | ||
@@ -56,3 +59,3 @@ let errorCount = 0 | ||
const worker = new Worker({ | ||
async task () { | ||
async task() { | ||
a += 1 | ||
@@ -64,7 +67,7 @@ | ||
}, | ||
onError (err) { | ||
onError(err) { | ||
errorCount += 1 | ||
lastError = err | ||
}, | ||
interval: 10 | ||
interval: 10, | ||
}) | ||
@@ -75,8 +78,8 @@ | ||
// make sure it ran at least twice | ||
t.true(a >= 2) | ||
t.is(errorCount, 1) | ||
t.true(lastError instanceof Error) | ||
t.is(lastError.message, 'Error the first time!') | ||
assert(a >= 2) | ||
assert(errorCount === 1) | ||
assert(lastError instanceof Error) | ||
assert(lastError.message === 'Error the first time!') | ||
worker.stop() | ||
}) |
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
0
0
Yes
4758
5
- Removedesm@^3.2.5
- Removedesm@3.2.25(transitive)