ReactiveX / ReactiveX/rxjs

mergeScan drops accumulator with async merging source

Open
#6,612 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
31.7k
Forks
3k
PR merge metrics
No merged PRs in 30d

Description

Bug Report

Current Behavior

sync

Rx.range(1, 3).pipe(

    Rx.mergeScan((acc, n) =>

        Rx.of([ ...acc, n ])

    , [ 0 ]),

).subscribe(console.log);

// [ 0, 1 ]
// [ 0, 1, 2 ]
// [ 0, 1, 2, 3 ]

async

Rx.range(1, 3).pipe(

    Rx.mergeScan((acc, n) =>

        Rx.of([ ...acc, n ]).pipe(
            Rx.delay(5),
        )

    , [ 0 ]),

).subscribe(console.log);

// [ 0, 1 ]
// [ 0, 2 ]
// [ 0, 3 ]

Expected behavior

Async accumulating as well as synced one.

Reproduction

stackblitz

Environment

  • Runtime: Node v12 v14 v16
  • RxJS version: v7.3.0

Possible Solution

Rx.range(1, 3).pipe(

    Rx.mergeScan((acc, n) =>

        Rx.of([ ...acc, n ]).pipe(
            Rx.delay(5),
        )

    , [ 0 ], 1),  // set concurrent to ONE works but loosing parallelism

).subscribe(console.log);

Additional context/Screenshots

#2737

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the linked StackBlitz reproduction and compare the synchronous and delayed mergeScan examples. Investigate the mergeScan behavior described in issue #2737, then verify that asynchronous accumulation retains prior values while preserving concurrency greater than one.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.