![]() The consumer sits at the opposite end of the flow stream and collects the values as they are emitted by the producer. As each data value becomes available, the producer emits that value to the flow. The code that retrieves the stream of data from our hypothetical network connection, for example, would be considered a producer. Producers are responsible for providing the data that makes up the flow. A stream of data arriving over time via a network connection would, for example, be an ideal situation for using a Kotlin flow.įlows are comprised of producers, intermediaries, and consumers. In the next chapter ( An Android SharedFlow Tutorial), we will look more closely at using SharedFlow within the context of Android app development Understanding Kotlin Flowsįlows are a part of the Kotlin programming language and are designed to allow multiple values to be returned sequentially from coroutine-based asynchronous tasks. In this chapter, we will introduce Kotlin Flows and explore how these can be used to return sequential streams of results from coroutine-based tasks.īy the end of the chapter, you should have a good understanding of the Flow, StateFlow, and SharedFlow Kotlin types, and appreciate the difference between hot and cold flow streams. As we have seen, coroutine suspend functions are ideal for performing tasks that return a single result value. ![]() The earlier chapter titled “An Introduction to Kotlin Coroutines” taught us about Kotlin Coroutines and explained how they can be used to perform multiple tasks concurrently without blocking the main thread.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |