https://kotlinlang.org logo
#coroutines
Title
# coroutines
j

Joan Colmenero

04/27/2020, 10:12 AM
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

Animesh Sahu

04/27/2020, 10:23 AM
Just add it
context+job+exceptionhandler
j

Joan Colmenero

04/27/2020, 10:37 AM
if I do this
Copy code
this.job.apply {
            CoroutineScope(context + CoroutineExceptionHandler { someError, error -> throw error })
                .launch { block(it) }
        }
will do the same?
a

Animesh Sahu

04/27/2020, 10:39 AM
No
You either need to use job in coroutine scope or pass it as a parameter to the launch(job) {}
j

Joan Colmenero

04/27/2020, 10:40 AM
I put the + job + and looks it works 🙂 thanks
a

Animesh Sahu

04/27/2020, 10:40 AM
😃☺️
2 Views