Skip to content

Commit

Permalink
fix: pass once: true to addEventListener
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfbecker committed Aug 30, 2018
1 parent 1238576 commit be96dac
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ export const toPromise = <T>(observable: Observable<T>, signal?: AbortSignal): P
}
)
if (signal) {
signal.addEventListener('abort', () => {
subscription.unsubscribe()
reject(createAbortError())
})
signal.addEventListener(
'abort',
() => {
subscription.unsubscribe()
reject(createAbortError())
},
{ once: true }
)
}
})

Expand Down Expand Up @@ -85,10 +89,14 @@ export const forEach = <T>(source: Observable<T>, next: (value: T) => void, sign
resolve
)
if (signal) {
signal.addEventListener('abort', () => {
subscription.unsubscribe()
reject(createAbortError())
})
signal.addEventListener(
'abort',
() => {
subscription.unsubscribe()
reject(createAbortError())
},
{ once: true }
)
}
})

Expand Down

0 comments on commit be96dac

Please sign in to comment.