initial commit
This commit is contained in:
commit
e2466b202a
50 changed files with 4356 additions and 0 deletions
25
utils/temp.ts
Normal file
25
utils/temp.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* Copyright (c) 2025 favewa
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
export async function withInterval<T>(
|
||||
callback: () => Promise<T>,
|
||||
seconds: number,
|
||||
): Promise<() => T> {
|
||||
let value: T = await callback();
|
||||
let timer: number | undefined;
|
||||
|
||||
async function tick() {
|
||||
clearInterval(timer);
|
||||
try {
|
||||
value = await callback();
|
||||
} catch (_) {
|
||||
// no-op
|
||||
}
|
||||
timer = setInterval(tick, seconds * 1000);
|
||||
}
|
||||
timer = setInterval(tick, seconds * 1000);
|
||||
|
||||
return () => value;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue