How can I assign a job (local variable) to a corou...
# coroutines
j
How can I assign a job (local variable) to a coroutineScope?
I have something like this :
Copy code
CoroutineScope(context + CoroutineExceptionHandler { someError, error -> throw error })
            .launch { block(it) }
But on my class I have a
val job = Job()
and I want to say that that job is this CoroutineScope
a
Just add it
context+job+exceptionhandler
j
if I do this
Copy code
this.job.apply {
            CoroutineScope(context + CoroutineExceptionHandler { someError, error -> throw error })
                .launch { block(it) }
        }
will do the same?
a
No
You either need to use job in coroutine scope or pass it as a parameter to the launch(job) {}
j
I put the + job + and looks it works 🙂 thanks
a
😃☺️