@nxtedition/lib 24.1.2 → 25.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 (2) hide show
  1. package/cache.js +15 -8
  2. package/package.json +1 -1
package/cache.js CHANGED
@@ -49,7 +49,11 @@ export class AsyncCache {
49
49
  }
50
50
  }
51
51
 
52
- async get(...args) {
52
+ /**
53
+ * @param {...any} args
54
+ * @returns {{ value: Promise<unknown>|unknown, async: boolean }}
55
+ */
56
+ get(...args) {
53
57
  const key = this.#keySelector(...args)
54
58
 
55
59
  if (typeof key !== 'string' || key.length === 0) {
@@ -62,7 +66,7 @@ export class AsyncCache {
62
66
  const now = Date.now()
63
67
 
64
68
  if (now < cached.expire) {
65
- return cached.value
69
+ return { value: cached.value, async: false }
66
70
  }
67
71
 
68
72
  if (now - cached.expire >= this.#stale(cached.value, key)) {
@@ -91,16 +95,19 @@ export class AsyncCache {
91
95
  }
92
96
 
93
97
  if (cached) {
94
- return cached.value
98
+ return { value: cached.value, async: false }
95
99
  }
96
100
 
97
- const [err, value] = await promise
101
+ return {
102
+ value: promise.then(([err, val]) => {
103
+ if (err) {
104
+ throw err
105
+ }
98
106
 
99
- if (err) {
100
- throw err
107
+ return val
108
+ }),
109
+ async: true,
101
110
  }
102
-
103
- return value
104
111
  }
105
112
 
106
113
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "24.1.2",
3
+ "version": "25.0.0",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",