Skip to content

Operator find does not unsubscribe on match #3934

@TPReal

Description

@TPReal

Bug Report

Current Behavior
The find operator does not unsubscribe from the source observable when a match is found, but rather only after the result observable is unsubscribed from. This means that find(()=>true) behaves differently from first(), and the behaviour of first() is better.

Reproduction
https://rxviz.com/v/1o7zEN08
https://stackblitz.com/edit/typescript-ghjbsy

// Test 1:
let test1='t1';
interval(200).pipe(
  take(10),
  // This happens only once as the interval is unsubscribed from after first() matches.
  tap(()=>test1+='-'),
  first(),
  delay(900),
  map(()=>test1),
).subscribe(v=>console.log(v));

// Test 2:
let test2='t2';
interval(200).pipe(
  take(10),
  // This happens many times because find does not unsubscribe on match.
  tap(()=>test2+='-'),
  find(()=>true),
  delay(900),
  map(()=>test2),
).subscribe(v=>console.log(v));

Expected behavior
Find should unsubscribe from the source when it matches the first element. It is not justified to hold the subscription as we know that no more elements from the source observable will be useful for us.

Environment

  • Runtime: Chrome 67.0.3396.87
  • RxJS version: 6.2.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions