mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-31 20:33:39 +00:00
add connection monitor to sources
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { BehaviorSubject, concat, from, Observable, of } from 'rxjs'
|
||||
import { BehaviorSubject, concat, from, Observable, of, Subject } from 'rxjs'
|
||||
import { concatMap, delay, skip, switchMap, take, tap } from 'rxjs/operators'
|
||||
import { Store } from '../store'
|
||||
import { Http, Update } from '../types'
|
||||
@@ -9,6 +9,7 @@ export type PollConfig = {
|
||||
}
|
||||
|
||||
export class PollSource<T> implements Source<T> {
|
||||
connectionMade$ = new Subject<void>()
|
||||
|
||||
constructor (
|
||||
private readonly pollConfig: PollConfig,
|
||||
@@ -34,14 +35,15 @@ export class PollSource<T> implements Source<T> {
|
||||
const poll$ = concat(updates$, delay$)
|
||||
|
||||
return polling$.pipe(
|
||||
switchMap(_ => poll$),
|
||||
concatMap(res => {
|
||||
switchMap(_ => poll$),
|
||||
concatMap(res => {
|
||||
this.connectionMade$.next()
|
||||
if (Array.isArray(res)) {
|
||||
return from(res) // takes Revision[] and converts it into Observable<Revision>
|
||||
} else {
|
||||
return of(res) // takes Dump<T> and converts it into Observable<Dump<T>>
|
||||
}
|
||||
}),
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user