mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
20 lines
445 B
TypeScript
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()
|
|
},
|
|
})
|
|
})
|