What is the difference between CoroutineContext and Job in kotlinx.coroutines?

There are kotlinx.coroutinesall coroutine constructors in the library , such as launch, asyncetc. accept a parameter CoroutineContext, but also have an additional parameter parentwith a type Job. What is the difference between CoroutineContextand Job?

+4
source share
1 answer

Jobrepresents a coroutine or some kind of aggregate task that is being performed. A Jobis this CoroutineContext.Element, which means that it can be saved in the context of a coroutine. CoroutineContextis a collection of different coroutine context elements, with the task being just one of those elements.

, coroutine , coroutine . , ctx CoroutineContext, ctx[Job]. CoroutineContext.

, . , .

parent coroutine, launch, . launch , , . , , .

+6

Source: https://habr.com/ru/post/1690367/


All Articles