Job Factory Function

Learn how to use job factory functions.

A Job can be created without a coroutine using the Job() factory function. It creates a job that isn’t associated with any coroutine, and we can use it as a context. This also means we can use such a job as a parent of many coroutines.

Creating jobs as parent contexts for coroutines

A common mistake is to create a job using the Job() factory function, use it as a parent for some coroutines, and then use join on the job. Such a program will never end because Job is still in an active state, even when all its children are finished. This is because this context is still ready to be used by other coroutines.

Get hands-on with 1200+ tech skills courses.