mentie 0.2.27 → 0.2.28

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 (2) hide show
  1. package/modules/cache.js +29 -0
  2. package/package.json +1 -1
package/modules/cache.js CHANGED
@@ -30,4 +30,33 @@ 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
+ * @returns {number} - The concurrency value.
40
+ */
41
+ export function concurrency( logger ) {
42
+
43
+ // Get the concurrency key
44
+ let key = cache( `concurrency_key` )
45
+ if( !key ) {
46
+ cache( `concurrency_key`, Date.now() )
47
+ key = cache( `concurrency_key` )
48
+ }
49
+
50
+ // Get the latest concurrency value
51
+ const concurrency = cache( `concurrency` ) || 1
52
+
53
+ // Set the new concurrency value
54
+ cache( `concurrency`, concurrency + 1 )
55
+
56
+ // If there was no logger, return the concurrency value
57
+ if( !logger ) return concurrency
58
+
59
+ // Log the concurrency value
60
+ logger( `Concurrency key ${ key }: ${ concurrency }` )
61
+
33
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mentie",
3
- "version": "0.2.27",
3
+ "version": "0.2.28",
4
4
  "description": "Mentor's toolbelt",
5
5
  "type": "module",
6
6
  "main": "index.js",