-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding onDispose #17
adding onDispose #17
Conversation
Codecov ReportPatch coverage:
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## main #17 +/- ##
=======================================
Coverage 99.36% 99.36%
=======================================
Files 110 110
Lines 1737 1739 +2
=======================================
+ Hits 1726 1728 +2
Misses 11 11
☔ View full report in Codecov by Sentry. |
Hmm, I don't think the separate dispose callback is facilitating a good (or even useful) coding practice. The creation callback can be called multiple times, and it is not clear how the dispose callback can then clean-up the correct corresponding state? I recommend that you create disposables during the creation callback: final observable = create<String>((emitter) {
emitter.next('a');
/* ... */
emitter.add(ActionDisposable(() => /* free expensive resource */));
}); Maybe there are some ways to make this code a bit more obvious? |
I agree with your new implementation, but maybe we should keep |
(Quoting myself)
I see that there is a significant difference between exposing an Initially implemented this by changing the signature of the
So the solution: emitter.add(ActionDisposable(() => /* free expensive resource */)); Has the least disadvantages aside of not being obvious. So maybe document it or add some: emitter.doOnDispose(() => /* free expensive resource */); |
Surprised that Making the callback accept a dynamic return value as in |
Let's follow that option then (I've pushed it). It may open doors for bugs, but other solutions has issues too and this one at least makes ground for when/if union types gets implemented. |
Unfortunately this breaks some of my code in very subtle ways, because the creation method happens to return something unrelated :-( |
The
rxjs
Observable
constructor allows passing asubscribe
function that returns aTeardowLogic
, which is a function that is called when subscription is cancelled. https://rxjs.dev/api/index/class/Observable#constructorThis PR adds a
onDispose
named parameter to thecreate
constructor with the same purpose.