xcraft-core-utils 4.3.9 → 4.4.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.
package/lib/job-queue.js CHANGED
@@ -32,18 +32,17 @@ class JobQueue {
32
32
  this.waitDelay = options.waitDelay;
33
33
  this.channel = name.toLowerCase().replace(/\.|\[|\//g, '-');
34
34
  this.runner = watt(function* (...args) {
35
- this.runningSamples++;
35
+ this.notify(++this.runningSamples, true);
36
36
  try {
37
37
  yield* runner(...args);
38
38
  } finally {
39
- this.endOfRunningSamples++;
39
+ this.notify(--this.runningSamples, true);
40
40
  }
41
41
  });
42
42
  this.parallelLimit = parallelLimit;
43
43
  this.waiting = new Map();
44
44
  this.running = 0;
45
45
  this.runningSamples = 0;
46
- this.endOfRunningSamples = 0;
47
46
  this._mutex = new locks.Mutex();
48
47
  const busClient = require('xcraft-core-busclient').getGlobal();
49
48
  this.resp = busClient.newResponse('job-queue', 'token');
@@ -55,15 +54,14 @@ class JobQueue {
55
54
  return this.attempt >= this.maxAttempt;
56
55
  }
57
56
 
58
- _notify(runningSamples) {
57
+ _notify(sample, hold) {
59
58
  this.resp.events.send('<job-queue.sampled>', {
60
59
  channel: this.channel,
61
- sample: runningSamples,
60
+ sample,
62
61
  current: 0,
63
62
  total: 0,
63
+ hold,
64
64
  });
65
- this.runningSamples -= this.endOfRunningSamples;
66
- this.endOfRunningSamples = 0;
67
65
  }
68
66
 
69
67
  _log() {
@@ -109,7 +107,7 @@ class JobQueue {
109
107
  }
110
108
 
111
109
  dispose() {
112
- this.notify(0);
110
+ this.notify(0, false);
113
111
  this.resp.events.send('<job-queue.disposed>', {
114
112
  channel: this.channel,
115
113
  });
package/lib/js.js CHANGED
@@ -1,14 +1,16 @@
1
1
  'use strict';
2
2
 
3
+ const AsyncFunction = (async () => {}).constructor;
4
+ const GeneratorFunction = function* () {}.constructor;
5
+
3
6
  exports.isFunction = function (fn) {
4
7
  return typeof fn === 'function';
5
8
  };
6
9
 
7
10
  exports.isGenerator = function (fn) {
8
- return (
9
- fn &&
10
- exports.isFunction(fn) &&
11
- fn.constructor &&
12
- fn.constructor.name === 'GeneratorFunction'
13
- );
11
+ return fn && fn instanceof GeneratorFunction === true;
12
+ };
13
+
14
+ exports.isAsync = function (fn) {
15
+ return fn && fn instanceof AsyncFunction === true;
14
16
  };
@@ -76,8 +76,6 @@ class Runner {
76
76
  }
77
77
  //end callback
78
78
 
79
- jobQueue.notify(jobQueue.runningSamples);
80
-
81
79
  //update counter
82
80
  jobQueue.running--;
83
81
  this.totalRunning--;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xcraft-core-utils",
3
- "version": "4.3.9",
3
+ "version": "4.4.0",
4
4
  "description": "Xcraft utils",
5
5
  "main": "index.js",
6
6
  "engines": {