![]() ![]() There are many more elements defined in the coroutines library, but these are the main ones that you would use in your code. CoroutineExceptionHandler - an element that handles uncaught exceptions.CoroutineId, CoroutineName - elements mainly used to debug coroutines.CoroutineDispatcher, MainCoroutineDispatcher - dispatchers for a coroutine to run on.Job - a cancellable handle to a coroutine with a lifecycle.Since CoroutineContext is nothing more than a container, the most important part is its content.Īn Element is anything a coroutine might need to run correctly. */ public operator fun get (key: Key): E? * Returns the element with the given from this context or `null`. We can access those Elements using a Key, just as we would in a normal Map: /** */ "1.3") public interface CoroutineContextĪs we can see from the KDoc, in broad terms, the CoroutineContext is just a Map that stores a set of Element objects that have a unique Key. ![]() * Every element in this set has a unique. * An indexed set is a mix between a set and a map. To kick this article off, let's take a look at the declaration of CoroutineContext: /** In Part 1 of my series about coroutines, I will take a close look at the CoroutineContext and discuss the best practices on how to use it. However, given its nature and flexible API, it might prove pretty tricky to use it correctly. Every coroutine you launch will have a context. The CoroutineContext is the backbone of the coroutines library. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |