Skip to content

Commit

Permalink
fix disposer issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nighca committed Nov 27, 2024
1 parent a512da0 commit 46184d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ watch(
framesDisposable.dispose()
return
}
disposable.addDisposer(framesDisposable.dispose)
disposable.addDisposable(framesDisposable)
if (soundSrc) {
const nextAudioElement = await preloadAudio(soundSrc)
Expand Down
12 changes: 10 additions & 2 deletions spx-gui/src/utils/disposable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,27 @@ import { Cancelled } from './exception'

export type Disposer = () => void

export class Disposable {
export interface IDisposable {
dispose(): void
}

export class Disposable implements IDisposable {
private disposers: Disposer[] = []

private _isDisposed = false
get isDisposed() {
return this._isDisposed
}

addDisposer = (disposer: Disposer) => {
addDisposer(disposer: Disposer) {
if (this._isDisposed) throw new Error('disposed')
this.disposers.push(disposer)
}

addDisposable(disposable: IDisposable) {
this.addDisposer(() => disposable.dispose())
}

dispose() {
if (this._isDisposed) return
this._isDisposed = true
Expand Down

0 comments on commit 46184d4

Please sign in to comment.