Sam
09/08/2022, 7:59 AMinline fun <T> foo(f: nosuspend () -> T): T
Sam
09/08/2022, 8:00 AMval threadLocal = ThreadLocal<String>()
inline fun <T> withFoo(f: () -> T):T = try {
threadLocal.set("foo")
f()
} finally {
threadLocal.remove()
}
suspend fun bar() {}
suspend fun main() {
withFoo { bar() } // I want this to be an error
}
I don’t want to be able to call bar()
inside withFoo
, because it would be an error to set a thread local and then suspendSam
09/08/2022, 8:01 AMSam
09/08/2022, 8:04 AMwithFoo
that I shared above is what I would write if coroutines didn’t exist. I want to be able to do that but ensure that nobody accidentally calls it with a suspending lambda. It’s as if the existence of coroutines is making my function signature unsafe 😕ephemient
09/08/2022, 8:05 AMSam
09/08/2022, 8:06 AMfranztesca
09/10/2022, 9:00 AMlouiscad
09/18/2022, 12:45 AMcrossinline
modifier.ephemient
09/18/2022, 1:16 AMlouiscad
09/18/2022, 1:18 AM