@nxtedition/lib 24.1.2 → 25.1.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/cache.js +15 -8
- package/package.json +1 -1
- package/time.js +12 -0
package/cache.js
CHANGED
|
@@ -49,7 +49,11 @@ export class AsyncCache {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
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
|
-
|
|
101
|
+
return {
|
|
102
|
+
value: promise.then(([err, val]) => {
|
|
103
|
+
if (err) {
|
|
104
|
+
throw err
|
|
105
|
+
}
|
|
98
106
|
|
|
99
|
-
|
|
100
|
-
|
|
107
|
+
return val
|
|
108
|
+
}),
|
|
109
|
+
async: true,
|
|
101
110
|
}
|
|
102
|
-
|
|
103
|
-
return value
|
|
104
111
|
}
|
|
105
112
|
|
|
106
113
|
/**
|
package/package.json
CHANGED
package/time.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
let fastNowTime = 0
|
|
2
|
+
|
|
3
|
+
export function fastNow() {
|
|
4
|
+
if (fastNowTime === 0) {
|
|
5
|
+
fastNowTime = Math.floor(Date.now() / 1e3) * 1e3
|
|
6
|
+
setInterval(() => {
|
|
7
|
+
fastNowTime = Math.floor(Date.now() / 1e3) * 1e3
|
|
8
|
+
}, 1e3).unref()
|
|
9
|
+
}
|
|
10
|
+
return fastNowTime
|
|
11
|
+
}
|
|
12
|
+
|
|
1
13
|
export function isTimeBetween(date, startTime, endTime, isUTC) {
|
|
2
14
|
let currentHours = date.getHours()
|
|
3
15
|
let currentMinutes = date.getMinutes()
|