remove poll altogether

This commit is contained in:
Matt Hill
2022-08-16 15:14:39 -06:00
parent caf53a9141
commit a8eaf2ca41
5 changed files with 14 additions and 55 deletions

View File

@@ -1,34 +0,0 @@
import { from, Observable, of, repeat } from 'rxjs'
import { concatMap, take } from 'rxjs/operators'
import { Store } from '../store'
import { Http, Update } from '../types'
import { Source } from './source'
export type PollConfig = {
cooldown: number
}
export class PollSource<T> implements Source<T> {
constructor(
private readonly pollConfig: PollConfig,
private readonly http: Http<T>,
) {}
watch$({ sequence$ }: Store<T>): Observable<Update<T> | null> {
return sequence$.pipe(
concatMap(seq => this.http.getRevisions(seq)),
take(1),
concatMap(res => {
// If Revision[]
if (Array.isArray(res)) {
// Convert Revision[] it into Observable<Revision> OR return null
return res.length ? from(res) : of(null)
// If Dump<T>
}
// Convert Dump<T> into Observable<Dump<T>>
return of(res)
}),
repeat({ delay: this.pollConfig.cooldown }),
)
}
}

View File

@@ -3,5 +3,5 @@ import { Store } from '../store'
import { Update } from '../types'
export interface Source<T> {
watch$(store?: Store<T>): Observable<Update<T> | null>
watch$(store?: Store<T>): Observable<Update<T>>
}

View File

@@ -7,6 +7,6 @@ export class WebsocketSource<T> implements Source<T> {
constructor(private readonly url: string) {}
watch$(): Observable<Update<T>> {
return webSocket<Update<T>>(this.url).pipe(timeout({ first: 60000 }))
return webSocket<Update<T>>(this.url).pipe(timeout({ first: 21000 }))
}
}