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
ZiplineScope #769
Comments
The light/loose convention for placing things into a So what about doing something like |
Discussed with @JakeWharton offline. One thing we decided is it’s probably best to create our own scope abstraction instead of borrowing the one from coroutines. That’ll feel lighter and likely be simpler to implement. We also decided that this works a bit like ownership tagging in a garbage collector, and it’s possible we can borrow ideas from that domain. We should be careful that the scope shouldn‘t artificially extend the visibility of a service if it’s closed manually with |
Here’s a start.
|
I’ve got an implementation idea that might work. I’ll assume no parent scopes as a simplification. The scope class is an ID wrapper that keeps track of which endpoints it has services on:
When doing a pass-by-reference, we take a scope ID from the
Finally,
(I’m not 100% sure I’ve got inbound/outbound all exactly right here! But I really like the option to make scopes IDs; it avoids all kinds of potential problems where scopes end up preventing services from being GC'd.) |
The implementation with IDs didn’t work 'cause the endpoint that knows the IDs doesn’t have a list of services to enumerate. But I got something that works regardless. With these PRs we’ve got a simple implementation that works nicely.
We’ve got a few remaining follow-ups, which I’ll create as separate tracking issues. |
It’s difficult bookkeeping to call
ZiplineService.close()
all the places it’s necessary to.Flow<T>
is even worse. I’ve found a case where aFlow
is never collected, and that causes it to leak. (We currently close flows after the first collect() completes; this is painful for both never collecting and also multiple collecting).I propose the following API:
One place this falls short is
Flow<T>
, which isn’t aZiplineService
. Worse, it’s difficult to get theZiplineService
from aFlow<T>
.We could do magic for inbound calls:
There’s a lot of room to experiment with syntax here, and I’m not particularly attached to the proposals above. But I do think there’s something handy to linking
ZiplineService.close()
to a coroutine scope.The text was updated successfully, but these errors were encountered: