Skip to content

Commit

Permalink
fix: Use take in delayUntil.
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Feb 23, 2020
1 parent 2b88ae9 commit 10e217c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
44 changes: 43 additions & 1 deletion source/operators/delayUntil-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,49 @@ describe("delayUntil", () => {
);

it(
"should support empty sources",
"should don't emit after the signal",
marbles(m => {
const source = m.cold(" -a-b------|");
const signal = m.cold(" -----x-----");
const subs = " ^---------!";
const expected = m.cold(" -----(ab)-|");

const destination = source.pipe(delayUntil(signal));
m.expect(destination).toBeObservable(expected);
m.expect(source).toHaveSubscriptions(subs);
})
);

it(
"should don't emit before the signal",
marbles(m => {
const source = m.cold(" -------a-b|");
const signal = m.cold(" -----x-----");
const subs = " ^---------!";
const expected = m.cold(" -------a-b|");

const destination = source.pipe(delayUntil(signal));
m.expect(destination).toBeObservable(expected);
m.expect(source).toHaveSubscriptions(subs);
})
);

it(
"should support empty sources that complete before the signal",
marbles(m => {
const source = m.cold(" ---| ");
const signal = m.cold(" -----x-");
const subs = " ^--! ";
const expected = m.cold(" ---| ");

const destination = source.pipe(delayUntil(signal));
m.expect(destination).toBeObservable(expected);
m.expect(source).toHaveSubscriptions(subs);
})
);

it(
"should support empty sources that complete after the signal",
marbles(m => {
const source = m.cold(" --------------|");
const signal = m.cold(" -----x---------");
Expand Down
4 changes: 2 additions & 2 deletions source/operators/delayUntil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
*/

import { concat, Observable, OperatorFunction } from "rxjs";
import { buffer, first, mergeAll, publish } from "rxjs/operators";
import { buffer, mergeAll, publish, take } from "rxjs/operators";

export function delayUntil<T>(
notifier: Observable<any>
): OperatorFunction<T, T> {
return source =>
source.pipe(
publish(published =>
concat(published.pipe(buffer(notifier), first(), mergeAll()), published)
concat(published.pipe(buffer(notifier), take(1), mergeAll()), published)
)
);
}

0 comments on commit 10e217c

Please sign in to comment.