zaraz 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/lib/zaraz.js +21 -20
  2. package/package.json +4 -2
  3. package/index.js +0 -1
package/lib/zaraz.js CHANGED
@@ -1,6 +1,6 @@
1
- const debug = require('debug')('zaraz');
1
+ import Debug from 'debug';
2
2
 
3
- module.exports = zaraz;
3
+ const debug = Debug('zaraz');
4
4
 
5
5
  const queues = {
6
6
  timer: undefined,
@@ -9,29 +9,30 @@ const queues = {
9
9
  later: []
10
10
  };
11
11
 
12
- const Item = {
13
- init(fn, params) {
14
- this._fn = fn;
15
- this._params = params;
16
- return this;
17
- },
12
+ class Item {
13
+ #fn;
14
+ #params;
15
+ constructor(fn, params) {
16
+ this.#fn = fn;
17
+ this.#params = params;
18
+ }
18
19
 
19
20
  run() {
20
21
  // bail if nothing to run
21
- if (!this._fn) { return; }
22
+ if (!this.#fn) return;
22
23
 
23
- const fn = this._fn;
24
+ const fn = this.#fn;
24
25
  this.clear();
25
- fn(...this._params);
26
- },
26
+ fn(...this.#params);
27
+ }
27
28
 
28
29
  clear() {
29
- this._fn = undefined;
30
+ this.#fn = undefined;
30
31
  }
31
- };
32
+ }
32
33
 
33
- function zaraz(fn, ...params) {
34
- const item = Object.create(Item).init(fn, params);
34
+ export default function zaraz(fn, ...params) {
35
+ const item = new Item(fn, params);
35
36
  const q = queues.index > 0 ? queues.later : queues.current;
36
37
  q.push(item);
37
38
 
@@ -39,9 +40,9 @@ function zaraz(fn, ...params) {
39
40
  return item;
40
41
  }
41
42
 
42
- zaraz.DELAY = 10; // default delay
43
- zaraz.ACTIVE = 100; // how long before we yield after processing items
44
- zaraz.MAX_ITEMS = 1000; // how many items we can process in a single step
43
+ zaraz.DELAY = 10; // default delay
44
+ zaraz.ACTIVE = 100; // how long before we yield after processing items
45
+ zaraz.MAX_ITEMS = 1000; // how many items we can process in a single step
45
46
 
46
47
  function execute() {
47
48
  const start = Date.now();
@@ -49,7 +50,7 @@ function execute() {
49
50
 
50
51
  debug('queues before', queues.current.length - queues.index, queues.later.length);
51
52
 
52
- while(queues.index < max) {
53
+ while (queues.index < max) {
53
54
  queues.current[queues.index++].run();
54
55
  if (Date.now() - start > zaraz.ACTIVE) {
55
56
  debug('breaking...');
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "zaraz",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "Cheap way to introduce short async delay.",
5
+ "type": "module",
6
+ "exports": "./index.js",
5
7
  "author": {
6
8
  "name": "Damian Krzeminski",
7
9
  "email": "pirxpilot@furkot.com",
@@ -22,7 +24,7 @@
22
24
  "debug": "*"
23
25
  },
24
26
  "devDependencies": {
25
- "@pirxpilot/jshint": "~3"
27
+ "@biomejs/biome": "^1.9.4"
26
28
  },
27
29
  "scripts": {
28
30
  "test": "make check"
package/index.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./lib/zaraz');