Last active
March 26, 2019 02:48
-
-
Save cartant/c5fe2bccefa3ba8c53081efa3f770f64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { concat, OperatorFunction, race, SchedulerLike, timer } from "rxjs"; | |
import { mapTo, publish } from "rxjs/operators"; | |
function startWithTimeout<T, S = T>( | |
value: S, | |
duration: number | Date, scheduler?: SchedulerLike | |
): OperatorFunction<T, S | T> { | |
return source => source.pipe(publish(published => race( | |
published, | |
concat(timer(duration, scheduler).pipe(mapTo(value)), published) | |
))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment