Files
Folo/packages/internal/utils/src/chain.ts
T
Innei 4d746522f1 refactor: remove unused files and clean up project structure
- Deleted obsolete configuration files and unused components across various packages.
- Updated package.json files to reflect the removal of dependencies.
- Cleaned up code by removing unnecessary exports and unused imports in multiple modules.

Signed-off-by: Innei <tukon479@gmail.com>
2025-04-28 20:58:51 +08:00

28 lines
630 B
TypeScript

import { sleep } from "./utils"
export class Chain {
private chain: Promise<void> = Promise.resolve()
private abortController = new AbortController()
next(fn: () => any | Promise<any>) {
const { signal } = this.abortController
this.chain = this.chain.then(() => {
if (signal.aborted) {
throw "Chain aborted"
}
return fn() || Promise.resolve()
})
}
wait(ms: number): this {
this.chain = this.chain.then(() => sleep(ms))
return this
}
abort() {
this.chain = Promise.resolve()
this.abortController.abort()
this.abortController = new AbortController()
}
}