Bilibili-Evolved/registry/lib/components/video/player/common/mini-rxjs/utils.ts
2022-10-12 23:27:58 +08:00

20 lines
445 B
TypeScript

import { Subject as SubjectReturnType } from './subject'
export const firstValueFrom = <T>(subject: SubjectReturnType<T>) =>
new Promise<T>((resolve, reject) => {
const unsubscribe = subject.subscribe({
next: (value: T) => {
resolve(value)
unsubscribe()
},
error: () => {
reject()
unsubscribe()
},
complete: () => {
reject()
unsubscribe()
},
})
})