-
Notifications
You must be signed in to change notification settings - Fork 61
More proper overloads with suspend handlers #413
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,13 @@ import com.jetbrains.rd.framework.impl.RdEndpoint | |
| import com.jetbrains.rd.util.lifetime.Lifetime | ||
| import com.jetbrains.rd.util.reactive.IScheduler | ||
| import com.jetbrains.rd.util.threading.SynchronousScheduler | ||
| import kotlinx.coroutines.CoroutineScope | ||
| import kotlinx.coroutines.CoroutineStart | ||
| import kotlinx.coroutines.async | ||
| import kotlin.coroutines.CoroutineContext | ||
| import kotlin.coroutines.EmptyCoroutineContext | ||
|
|
||
| @Deprecated("Use the overload with CoroutineScope and CoroutineContext and pass all required context elements") | ||
| fun <TReq, TRes> IRdEndpoint<TReq, TRes>.setSuspend( | ||
| cancellationScheduler: IScheduler? = null, | ||
| handlerScheduler: IScheduler? = null, | ||
|
|
@@ -21,4 +26,25 @@ fun <TReq, TRes> IRdEndpoint<TReq, TRes>.setSuspend( | |
| set(cancellationScheduler, handlerScheduler) { lt, req -> | ||
| lt.startAsync(coroutineDispatcher) { handler(lt, req) }.toRdTask() | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Sets suspend handler for the [IRdEndpoint]. | ||
| * | ||
| * When a protocol call is occurred it starts a new coroutine on [scope] passing [coroutineContext] and [coroutineStart] to it. | ||
| * [cancellationScheduler] and [handlerScheduler] are passed to [IRdEndpoint.set] | ||
| */ | ||
| fun <TReq, TRes> IRdEndpoint<TReq, TRes>.setSuspend( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be honest, I find this method a little strange
So I believe that we don't need that kind of API in the platform, because that API has a lot of non-obvious and contradictory moments, but at the same time it's easy to write that kind of code in your specific case. I would prefer that kind of API: Or we can use protocol dispatcher in case if coroutine context doesn't have corotineDispatcher |
||
| scope: CoroutineScope, | ||
| coroutineContext: CoroutineContext = EmptyCoroutineContext, | ||
| coroutineStart: CoroutineStart = CoroutineStart.DEFAULT, | ||
| cancellationScheduler: IScheduler? = null, | ||
| handlerScheduler: IScheduler? = null, | ||
| handler: suspend (Lifetime, TReq) -> TRes | ||
| ) { | ||
| set(cancellationScheduler, handlerScheduler) { lt, req -> | ||
| scope.async(coroutineContext, coroutineStart) { | ||
| handler(lt, req) | ||
| }.toRdTask() | ||
| } | ||
| } | ||
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 don't see any reason do deprecate this method, and more over force people to pass CoroutineScope here