Refactor the rqbit-web file by breaking it down into components and helper functions. Improve code organization and maintainability
This commit is contained in:
parent
a5e7a5a5f5
commit
f978ad02fe
25 changed files with 1722 additions and 926 deletions
27
crates/librqbit/webui/src/helper/loopUntilSuccess.ts
Normal file
27
crates/librqbit/webui/src/helper/loopUntilSuccess.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
export function loopUntilSuccess<T>(
|
||||
callback: () => Promise<T>,
|
||||
interval: number
|
||||
): () => void {
|
||||
let timeoutId: number;
|
||||
|
||||
const executeCallback = async () => {
|
||||
let retry = await callback().then(
|
||||
() => false,
|
||||
() => true
|
||||
);
|
||||
if (retry) {
|
||||
scheduleNext();
|
||||
}
|
||||
};
|
||||
|
||||
let scheduleNext = (overrideInterval?: number) => {
|
||||
timeoutId = setTimeout(
|
||||
executeCallback,
|
||||
overrideInterval !== undefined ? overrideInterval : interval
|
||||
);
|
||||
};
|
||||
|
||||
scheduleNext(0);
|
||||
|
||||
return () => clearTimeout(timeoutId);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue