Files
ArtPlayer/packages/artplayer-plugin-dash-control/src/cleanup.ts
T

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
}