@filen/utils 0.0.7 → 0.0.8
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/dist/run.js +17 -5
- package/dist/time.js +2 -6
- package/package.json +1 -1
package/dist/run.js
CHANGED
|
@@ -220,16 +220,15 @@ export class TimeoutError extends Error {
|
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
222
|
export async function runTimeout(fn, timeoutMs, options) {
|
|
223
|
-
|
|
223
|
+
let timeoutId = null;
|
|
224
224
|
try {
|
|
225
225
|
const result = await Promise.race([
|
|
226
226
|
run(fn, options),
|
|
227
227
|
new Promise((_, reject) => {
|
|
228
|
-
|
|
229
|
-
|
|
228
|
+
timeoutId = setTimeout(() => {
|
|
229
|
+
timeoutId = null;
|
|
230
230
|
reject(new TimeoutError(`Operation timed out after ${timeoutMs}ms`));
|
|
231
231
|
}, timeoutMs);
|
|
232
|
-
controller.signal.addEventListener("abort", () => clearTimeout(timeoutId));
|
|
233
232
|
})
|
|
234
233
|
]);
|
|
235
234
|
return result;
|
|
@@ -245,11 +244,17 @@ export async function runTimeout(fn, timeoutMs, options) {
|
|
|
245
244
|
error: e
|
|
246
245
|
};
|
|
247
246
|
}
|
|
247
|
+
finally {
|
|
248
|
+
if (timeoutId !== null) {
|
|
249
|
+
clearTimeout(timeoutId);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
248
252
|
}
|
|
249
253
|
export function runDebounced(fn, delayMs, options) {
|
|
250
254
|
let timeoutId = null;
|
|
251
255
|
let pendingResolve = null;
|
|
252
256
|
let pendingPromise = null;
|
|
257
|
+
let executing = false;
|
|
253
258
|
return (...args) => {
|
|
254
259
|
if (timeoutId) {
|
|
255
260
|
clearTimeout(timeoutId);
|
|
@@ -260,8 +265,15 @@ export function runDebounced(fn, delayMs, options) {
|
|
|
260
265
|
});
|
|
261
266
|
}
|
|
262
267
|
timeoutId = setTimeout(async () => {
|
|
268
|
+
if (executing || !pendingResolve) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
executing = true;
|
|
263
272
|
const result = await run(defer => fn(defer, ...args), options);
|
|
264
|
-
|
|
273
|
+
executing = false;
|
|
274
|
+
if (pendingResolve) {
|
|
275
|
+
pendingResolve(result);
|
|
276
|
+
}
|
|
265
277
|
pendingPromise = null;
|
|
266
278
|
pendingResolve = null;
|
|
267
279
|
timeoutId = null;
|
package/dist/time.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
export function isTimestampSameDay(timestamp1, timestamp2) {
|
|
2
2
|
const diff = timestamp1 - timestamp2;
|
|
3
|
-
if (diff
|
|
4
|
-
|
|
5
|
-
const day2 = Math.floor(timestamp2 / 86400000);
|
|
6
|
-
if (day1 === day2) {
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
3
|
+
if (diff < -86400000 || diff > 86400000) {
|
|
4
|
+
return false;
|
|
9
5
|
}
|
|
10
6
|
const date1 = new Date(timestamp1);
|
|
11
7
|
const date2 = new Date(timestamp2);
|