Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Fix withFallback to emit from main even if fallback has emitted #57

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/lang-go.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
combineLatest,
ObservableInput,
merge,
timer,
} from 'rxjs'
import {
concatMap,
Expand Down Expand Up @@ -557,12 +558,14 @@ function withFallback<T>({
fallback: ObservableInput<T>
delayMilliseconds: number
}): Observable<T> {
return race(
of(null).pipe(switchMap(() => from(main))),
const mainObservable = from(main).pipe(share())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrismwendt this is the best I could come up with to express "emit from fallback after delay, unless main has emitted, and emit everything from main". Happy to take suggestions on this 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented this independently and came up with exactly the same solution 😺

return merge(
of(null).pipe(
delay(delayMilliseconds),
switchMap(() => from(fallback))
)
switchMap(() => from(fallback)),
takeUntil(mainObservable)
),
mainObservable
)
}

Expand Down