Add `start` method to Observers
See original GitHub issueThe 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:
- Created 6 years ago
- Comments:9 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Regardless, I think we’re going to move away from the
start
method if we useabortSignal
: #3122This 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.