-
Notifications
You must be signed in to change notification settings - Fork 226
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
Add AutoDisposeContext + withScope functions #375
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish there was a way to let go of the autoDispose()
and then it would read exactly like Flow but alas.
@@ -253,3 +254,48 @@ inline fun <T> ParallelFlowable<T>.autoDisposable(provider: ScopeProvider): Para | |||
@CheckReturnValue | |||
inline fun <T> ParallelFlowable<T>.autoDispose(provider: ScopeProvider): ParallelFlowableSubscribeProxy<T> = | |||
this.`as`(AutoDispose.autoDisposable(provider)) | |||
|
|||
/** Executes a [body] with under an [AutoDisposeContext] backed by the given [scope]. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you want with
or under
? i.e
Executes a [body] under an ....
or
Executes a [body] with an...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
|
||
/** | ||
* A context intended for use as `AutoDisposeCoroutineScope.() -> Unit` function body parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this is in the autodispose
module and that you can use it with a normal ScopeProvider
as well, we can probably skip the reference to coroutines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a stale doc from the original PR, will fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding convenience functions like: fun withScope(coroutineScope: CoroutineScope, body: AutoDisposeContext.() -> Unit) {
withScope(coroutineScope.toScopeProvider(), body)
}
in the Can do in a followup if you want. |
I don't like it in this case tbh. I think convenience functions make sense for discoverability and shorthands for common cases, but that case isn't either of those. |
Given that |
withContext is not a scoping construct like this is though, whereas this is a scoping construct and not doing anything implicitly with the block passed in other than affording it extra APIs. withContext will execute your block on a different context. I thought about calling this AutoDisposeScope at first, but context in this case in reference to the context that those extension functions are available. It's best not to think of this as having anything to do with coroutines or coroutine scope because it's unrelated functionality. The only thing in common really is that they use higher order functions with receivers :) |
Also - I think a good API boundary here is supporting AutoDispose's core types, and anything else that can be interop'd back to them should just use that. Otherwise it's a slippery slop to supporting anything that Completable and ScopeProvider can interop out to: CoroutineScope, LifecycleProvider (2 and 3), etc. If someone wants to write their own extension function to get the API you're describing, great! But otherwise I feel pretty strongly about keeping the API surface area here down to just AutoDispose's own core components. |
Yeah I strongly agree with that. Given the nature of composability of Rx, we'd end up supporting lots of overloads. The little inkling was mainly because of the similarity in names but it's only a minor inconvenience for people to just do |
This allows for some more idiomatic kotlin usage like so: