pakoito
04/05/2019, 12:31 PMaballano
04/05/2019, 1:32 PMfun <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 xDCause: 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
pakoito
04/05/2019, 1:45 PMaballano
04/05/2019, 1:50 PMpakoito
04/05/2019, 1:59 PMaballano
04/05/2019, 2:03 PMcontinueOn(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 👍.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 🤔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)
} }
pakoito
04/05/2019, 2:08 PMaballano
04/05/2019, 3:38 PM