Skip to content

Instantly share code, notes, and snippets.

@cartant
Last active March 26, 2019 02:48
Show Gist options
  • Save cartant/c5fe2bccefa3ba8c53081efa3f770f64 to your computer and use it in GitHub Desktop.
Save cartant/c5fe2bccefa3ba8c53081efa3f770f64 to your computer and use it in GitHub Desktop.
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