mentie 0.2.27 → 0.2.29
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/modules/cache.js +30 -0
- package/package.json +1 -1
package/modules/cache.js
CHANGED
|
@@ -30,4 +30,34 @@ export function cache( key, value ) {
|
|
|
30
30
|
|
|
31
31
|
if( value ) _cache[key] = value
|
|
32
32
|
return _cache[key]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Function to inspect concurrency.
|
|
37
|
+
*
|
|
38
|
+
* @param {Function} logger - The logger function.
|
|
39
|
+
* @param {string} key_prefix - The key for the concurrency value, used to tag the logging
|
|
40
|
+
* @returns {number} - The concurrency value.
|
|
41
|
+
*/
|
|
42
|
+
export function concurrency( logger, key_prefix ) {
|
|
43
|
+
|
|
44
|
+
// Get the concurrency key
|
|
45
|
+
let key = cache( `concurrency_key` )
|
|
46
|
+
if( !key ) {
|
|
47
|
+
cache( `concurrency_key`, `${ key_prefix }_${ Date.now() }` )
|
|
48
|
+
key = cache( `concurrency_key` )
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Get the latest concurrency value
|
|
52
|
+
const concurrency = cache( `concurrency` ) || 1
|
|
53
|
+
|
|
54
|
+
// Set the new concurrency value
|
|
55
|
+
cache( `concurrency`, concurrency + 1 )
|
|
56
|
+
|
|
57
|
+
// If there was no logger, return the concurrency value
|
|
58
|
+
if( !logger ) return concurrency
|
|
59
|
+
|
|
60
|
+
// Log the concurrency value
|
|
61
|
+
logger( `Concurrency key ${ key }: ${ concurrency }` )
|
|
62
|
+
|
|
33
63
|
}
|