mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-09-14 21:46:35 +00:00
feat: add pipeline for multi instrument flow
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
export function createAutoRunner(delayMs = 300) {
|
||||
let token = 0;
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
return {
|
||||
next(): number {
|
||||
cancelTimer();
|
||||
return ++token;
|
||||
},
|
||||
isCurrent(t: number): boolean {
|
||||
return t === token;
|
||||
},
|
||||
schedule(run: () => void): () => void {
|
||||
cancelTimer();
|
||||
timer = setTimeout(run, delayMs);
|
||||
return cancelTimer;
|
||||
}
|
||||
};
|
||||
|
||||
function cancelTimer() {
|
||||
if (timer !== undefined) {
|
||||
clearTimeout(timer);
|
||||
timer = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user