doing it blocking is trivial, but if you reentrant...
# arrow-contributors
p
doing it blocking is trivial, but if you reentrantly call into the main thread, as you saw with runBlocking, it never completes
a
would it work by changing this? https://github.com/arrow-kt/arrow/blob/master/modules/effects/arrow-effects-data/src/main/kotlin/arrow/effects/typeclasses/suspended/FxSyntax.kt#L50 to something like?
Copy code
fun <A> CoroutineContext.effect(continueOn: CoroutineContext = EmptyCoroutineContext, f: suspend () -> A): Kind<F, A> =
    asyncOp { defer(this@effect) { f.effect() }.continueOn(continueOn) }
I mean I just tried on arrow but got an error xD
Copy code
Cause: Cannot serialize error type: [ERROR : Unknown type parameter 1]
File being compiled at position: file:///Users/aballano/workspace/arrow/modules/effects/arrow-effects-data/src/main/kotlin/arrow/effects/typeclasses/ConcurrentCancellableContinuations.kt
The root cause was thrown at: SerializerExtension.kt:83
p
clean rebuild
👍 1
a
shall I create a PR and continue the discussion there?
or doesn't make sense to go this way?
p
there are a couple of potential complications with that approach, because we'd be clearing the CoroutineContext
the design of the thing requires that to override the Dispatcher you need the pre-existing context
and smash it together
this is a problem through the library -.-
a
so this means it might be improved, right? That's even better since this right now would essentially be saving the implementation client to manually
continueOn(UI)
after doing the effect anyway, no? So worst case scenario we save the client one line 👌 and best we even improve over what they would do manually otherwise 👍
or would that
.continueOn(EmptyCoroutineContext)
break something for the caller in case they don't specify the
CoroutineContext
? In such case we could just if-else and not call
continueOn
at all 🤔
Copy code
fun <A> CoroutineContext.effect(
          continueOn: CoroutineContext = EmptyCoroutineContext, 
          f: suspend () -> A
  ): Kind<F, A> =
    asyncOp { defer(this@effect) { f.effect() }.apply {
        if (continueOn != EmptyCoroutineContext) continueOn(continueOn)
    } }
p
I suggest adding a new API instead of modifying this one and matching on type
effectAndReturn or something like that
that way the additional parameter is unmissable, and the API name specifies what it does
👍 1