Skip to content

Commit

Permalink
fix: Delay completion in delayUntil.
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Feb 24, 2020
1 parent f7fbc18 commit 667be7a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
20 changes: 17 additions & 3 deletions source/operators/delayUntil-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,26 @@ describe("delayUntil", () => {
);

it(
"should support empty sources that complete before the signal",
"should delay sources that complete before the signal",
marbles(m => {
const source = m.cold(" -ab| ");
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 delay 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 expected = m.cold(" -----| ");

const destination = source.pipe(delayUntil(signal));
m.expect(destination).toBeObservable(expected);
Expand All @@ -79,7 +93,7 @@ describe("delayUntil", () => {
);

it(
"should support sources that error before the signal",
"should not delay errors before the signal",
marbles(m => {
const source = m.cold(" --# ");
const signal = m.cold(" -----x-");
Expand Down
7 changes: 5 additions & 2 deletions source/operators/delayUntil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* can be found in the LICENSE file at https://github.com/cartant/rxjs-etc
*/

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

export function delayUntil<T>(
Expand All @@ -12,7 +12,10 @@ export function delayUntil<T>(
return source =>
source.pipe(
publish(published =>
concat(published.pipe(buffer(notifier), take(1), mergeAll()), published)
concat(
concat(published, NEVER).pipe(buffer(notifier), take(1), mergeAll()),
published
)
)
);
}

0 comments on commit 667be7a

Please sign in to comment.