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

Paul Woitaschek

07/09/2019, 2:49 PM
s

streetsofboston

07/09/2019, 2:50 PM
Not sure…. because
CoroutineScope.cancel()
does just that…. maybe someone didn’t realize this extension method existed 🙂
s

streetsofboston

07/09/2019, 2:53 PM
I’m not sure how
closeWithRuntimeException
explains this..
p

Paul Woitaschek

07/09/2019, 2:54 PM
It's called by
clear
. They have a map where they put all sorts of stuff inside and if it's cancellable they cancel it. That's why they made a custom scope that implements cancellable.
1
s

streetsofboston

07/09/2019, 2:54 PM
Ah… it’s not about calling
this.cancel()
vs
coroutineContext.cancel()
. Your question is about why calling it through a
Closable
interface…
p

Paul Woitaschek

07/09/2019, 2:55 PM
I actually had 2 questions but only asked one 😄 So back to my original question: Is that completely equivalent? (cancelling the context vs cancelling the scope)
s

streetsofboston

07/09/2019, 2:56 PM
Yup. It looks like it. Just do ‘go to definition’ in your IDE of both extension functions and see how they’re implemented; basically the same.
3 Views