"Copy" coroutine context from outer scope

Hello there,
Any idea why this doesn’t work at runtime:

coroutineScope.future(coroutineScope.coroutineContext) {

My naive goal is to start a future with the same context as the outer scope. Any idea how to fix it?

Thanks,

Simple coroutineScope.future {} should do what you ask. How do you observe it doesn’t use the context of coroutineScope?

2 Likes

Ah, I understand the problem, I am using ThreadLocals in the coroutine context with threadLocal.asContextElement(...) and those do not get copied.

Thanks for the quick reply.