Is it possible to create a `CoroutineContext` from...
# kotlin-native
y
Is it possible to create a
CoroutineContext
from iOS and inject that into a kotlin/native class?
g
Yes, context is part of coroutines API
But it really depends what kind implementation do you want tot put to this context, because by default it’s just a container for metdata
y
I’m not sure what i’m doing wrong, but I can’t seem to instantiate one on the iOS side. I can’t see it in the header file.
g
How do you instantiating it? Not every context implementation is available on every platform
y
I have a kotlin class which takes in a
CoroutineContext
in it’s init:
Copy code
class Calculation(
    val coroutineContext: CoroutineContext)
and we have a method in the class which also performs the following:
Copy code
if (runningJob?.isActive != true) {
            runningJob = launch(coroutineContext) {
                update(value)
            }
        }
So i wanted to instantiate this class from the iOS side
And i wanted to create the
CoroutineContext
from the ios side - is this the right approach?
s
Have you tried adding Kotlin function creating proper
CoroutineContext
and then calling it from the iOS side?
y
Initially we had
val coroutineContext: CoroutineContext = newSingleThreadContext("CalculationThread")
but it’s not available in kotlin-common
Specifically the
newSingleThreadContext
s
newSingleThreadContext
is not available, please try other options to create new context.