question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add `start` method to Observers

See original GitHub issue

The TC39 spec has a start method to prevent this scenario from being a problem:

const subscription = range(0, 10000000).subscribe({
  next(value) { 
    if (value > 3) {
      // try to unsubscribe here, I dare you.
      subscription.unsubscribe();
    }
  }
});

The solution was to add an optional start method to Observer:

const subscription = range(0, 10000000).subscribe({
  start(subs) { this.subscription = subs; },
  next(value) { 
    if (value > 3) {
      // this.subscription is literally the same reference you'd get back
      // from the subscribe call itself.
      this.subscription.unsubscribe();
    }
  }
});

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
benleshcommented, Nov 16, 2017

Regardless, I think we’re going to move away from the start method if we use abortSignal: #3122

0reactions
lock[bot]commented, Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

addObserver() method, of observer pattern and object variable ...
Observable has a vector which holds the reference to all the observers that have been registered using the addObserver() method.
Read more >
Java.util.Observable.addObserver() Method - Tutorialspoint
The java.util.addObserver(Observer o) method adds the specified observer o to the set of observers for this object if, the observer is not the...
Read more >
Observers in Swift - Part 1
Above you can see that we call a stateDidChange() method each time the state of the player changes. Our main task will be...
Read more >
How to: Implement an Observer | Microsoft Learn
Define a method that enables the observer to stop receiving notifications before the provider calls its IObserver<T>.
Read more >
Observable (Java Platform SE 7 ) - Oracle Help Center
This class represents an observable object, or "data" in the model-view paradigm. It can be subclassed to represent an object that the application...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found