Łukasz Gendek
05/23/2022, 7:33 AMsimon.vergauwen
05/23/2022, 12:31 PMdivide1
works. What happens if you try to call kotlinx.coroutines.delay
from divide1
?
It should not be possible since EagerEffectScope<*>
doesn't allow foreign suspension.simon.vergauwen
05/23/2022, 12:31 PMdivide1
and divide2
is that this
is different due to how context receivers vs extension functions are currently implemented. this
is not properly recognized, at least not by IDEA hints. (not sure if this will change)simon.vergauwen
05/23/2022, 12:32 PMsuspend + EagerEffectScope<String>
belongs together, and it allows you to call EagerEffectScope#ensure
which is great!
But due to how currently context receivers are implemented it doesn't recognize that the suspend fun ensure
usage belongs to the context so it's valid.Łukasz Gendek
05/23/2022, 1:48 PMsimon.vergauwen
05/23/2022, 2:13 PMRestrictSuspension
annotation on EagerEffectScope
itself.
It seems that it's properly taken into account for extension functions, but not context receivers.
@RestrictSuspension
interface Example {
suspend fun test(): Unit
}
suspend fun Example.works(): Unit = test()
context(Example)
suspend fun doesNotWork(): Unit = test()
I assume it's more tricky for context receivers, because what should happen if we add a second receiver? Then it would no longer be correct due to RestrictSuspension
.simon.vergauwen
05/23/2022, 2:13 PMŁukasz Gendek
05/23/2022, 4:02 PM@RestrictSuspension
interface Example {
suspend fun test(): Unit
suspend fun works(): Unit = test()
}
What should happen when we add a receiver extension to the 'works' function in the example above? It is similar question to the one you are asking. Question already addressed long before context receivers were introduced.simon.vergauwen
05/23/2022, 4:22 PMWhat should happen when we add an extension receiver to the 'works' function in the example above?Nothing, the
test
invocation inside work
is correct. Afaik there is no extension receiver you can add to work
to break the usage of test
.
I think I phrased it a bit incorrectly. And when looking at the documentation it's stated much more clearly.
```Classes and interfaces marked with this annotation are restricted when used as receivers for extension
functions. Thesesuspend
extensions can only invoke other member or extensionsuspend
functions on this particularsuspend
receiver and are restricted from calling arbitrary suspension functions.```when used as receivers for extension
suspend
functions, so it only applies when used as receiver extensions. Which is what EagerEffectScope
does to enable the DSL inside eagerEffect
, and this is why you could call ensure
when you had EagerEffectScope
as the receiver extension.
Context receivers are not equivalent to the receiver extension since the receiver extension is semantically the same as a "member", whilst context receivers imply the types are available in the enviroment around us.simon.vergauwen
05/23/2022, 4:23 PMŁukasz Gendek
05/25/2022, 4:48 PMsimon.vergauwen
05/25/2022, 5:17 PMEagerEffectScope
the extension function style in that case. Do you have a significant reason that you want to use it with context receiver instead? I would absolutely not recommend using runBlocking, and I advise to not use it anywhere except fun main(): Unit = runBlocking {
simon.vergauwen
05/25/2022, 5:18 PMsuspend
if Kafka Stream has any support for Future
or KafkaFuture
(from Kafka SDK)Łukasz Gendek
12/20/2022, 9:30 AM