Skip to content

Instantly share code, notes, and snippets.

@vitaly-t
Last active October 7, 2021 16:50
Show Gist options
  • Save vitaly-t/4cd75c08640129ae736cb487b22f16a3 to your computer and use it in GitHub Desktop.
Save vitaly-t/4cd75c08640129ae736cb487b22f16a3 to your computer and use it in GitHub Desktop.
/**
* Drains the source observable till it completes, and then posts a new value-observable.
*/
function drain<T>(value: T | Observable<T> | (() => T | Observable<T>)) {
const v = () => {
const a = typeof value === 'function' ? value.call(null) : value;
return a instanceof Observable ? a : of(a);
}
return s => defer(() => s.pipe(filter(_ => false), c => concat(c, v()))) as Observable<T>;
}
function startTimer() {
return drain(Date.now);
}
// SEE: https://stackoverflow.com/questions/69472548/remap-rxjs-observable-to-a-timer-start-without-stream-interruption
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment