mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-17 18:11:20 -08:00
22 lines
412 B
TypeScript
22 lines
412 B
TypeScript
import type { Cleanup, Valid } from './types'
|
|
|
|
export function runCleanups(actions: Cleanup[], current: Valid = () => true): void {
|
|
let failed = false
|
|
let failure: unknown
|
|
for (const action of actions) {
|
|
if (!current())
|
|
break
|
|
try {
|
|
action()
|
|
}
|
|
catch (error) {
|
|
if (!failed) {
|
|
failed = true
|
|
failure = error
|
|
}
|
|
}
|
|
}
|
|
if (failed)
|
|
throw failure
|
|
}
|