@naturalcycles/nodejs-lib 13.34.5 → 13.34.6
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.
|
@@ -49,7 +49,7 @@ function transformThrottle(opt) {
|
|
|
49
49
|
// console.log('pausing now after', {item, count})
|
|
50
50
|
paused = (0, js_lib_1.pDefer)();
|
|
51
51
|
if (debug) {
|
|
52
|
-
console.log(`${js_lib_1.localTime.now().toPretty()} transformThrottle activated: ${count} items passed in ${(0, js_lib_1.
|
|
52
|
+
console.log(`${js_lib_1.localTime.now().toPretty()} transformThrottle activated: ${count} items passed in ${(0, js_lib_1._since)(start)}, will pause for ${(0, js_lib_1._ms)(interval * 1000 - (Date.now() - start))}`);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
cb(null, item); // pass the item through
|
|
@@ -60,15 +60,20 @@ function transformThrottle(opt) {
|
|
|
60
60
|
},
|
|
61
61
|
});
|
|
62
62
|
function onInterval(transform) {
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
if (paused) {
|
|
64
|
+
if (debug) {
|
|
65
|
+
console.log(`${js_lib_1.localTime.now().toPretty()} transformThrottle resumed`);
|
|
66
|
+
}
|
|
67
|
+
paused.resolve();
|
|
68
|
+
paused = undefined;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
if (debug) {
|
|
72
|
+
console.log(`${js_lib_1.localTime.now().toPretty()} transformThrottle passed ${count} (of max ${throughput}) items in ${(0, js_lib_1._since)(start)}`);
|
|
73
|
+
}
|
|
67
74
|
}
|
|
68
75
|
count = 0;
|
|
69
76
|
start = Date.now();
|
|
70
77
|
timeout = setTimeout(() => onInterval(transform), interval * 1000);
|
|
71
|
-
paused.resolve();
|
|
72
|
-
paused = undefined;
|
|
73
78
|
}
|
|
74
79
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Transform } from 'node:stream'
|
|
2
2
|
import {
|
|
3
3
|
_ms,
|
|
4
|
+
_since,
|
|
4
5
|
DeferredPromise,
|
|
5
6
|
localTime,
|
|
6
7
|
NumberOfMilliseconds,
|
|
@@ -75,7 +76,7 @@ export function transformThrottle<T>(opt: TransformThrottleOptions): TransformTy
|
|
|
75
76
|
paused = pDefer()
|
|
76
77
|
if (debug) {
|
|
77
78
|
console.log(
|
|
78
|
-
`${localTime.now().toPretty()} transformThrottle activated: ${count} items passed in ${
|
|
79
|
+
`${localTime.now().toPretty()} transformThrottle activated: ${count} items passed in ${_since(start)}, will pause for ${_ms(interval * 1000 - (Date.now() - start))}`,
|
|
79
80
|
)
|
|
80
81
|
}
|
|
81
82
|
}
|
|
@@ -89,16 +90,23 @@ export function transformThrottle<T>(opt: TransformThrottleOptions): TransformTy
|
|
|
89
90
|
})
|
|
90
91
|
|
|
91
92
|
function onInterval(transform: Transform): void {
|
|
92
|
-
if (
|
|
93
|
+
if (paused) {
|
|
94
|
+
if (debug) {
|
|
95
|
+
console.log(`${localTime.now().toPretty()} transformThrottle resumed`)
|
|
96
|
+
}
|
|
93
97
|
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
paused.resolve()
|
|
99
|
+
paused = undefined
|
|
100
|
+
} else {
|
|
101
|
+
if (debug) {
|
|
102
|
+
console.log(
|
|
103
|
+
`${localTime.now().toPretty()} transformThrottle passed ${count} (of max ${throughput}) items in ${_since(start)}`,
|
|
104
|
+
)
|
|
105
|
+
}
|
|
96
106
|
}
|
|
97
107
|
|
|
98
108
|
count = 0
|
|
99
109
|
start = Date.now()
|
|
100
110
|
timeout = setTimeout(() => onInterval(transform), interval * 1000)
|
|
101
|
-
paused.resolve()
|
|
102
|
-
paused = undefined
|
|
103
111
|
}
|
|
104
112
|
}
|