-
Notifications
You must be signed in to change notification settings - Fork 0
S3 Multi Threading
Nicolás Rueda edited this page Nov 7, 2023
·
14 revisions
Strategy | Description |
---|---|
Coroutines/launch | Coroutines are a key concept in Kotlin that enable asynchronous concurrency. They provide a simple and efficient way to write asynchronous code that is easy to read and maintain. Coroutines allow code to be executed asynchronously without blocking the main thread. In the first example, CoroutineScope.launch is used to perform background tasks on the I/O thread. Dispatchers.IO is utilized for working with I/O or performing network operations, and Dispatchers.Main is used to make UI changes after the background operation is completed. The launch method is used to start a new coroutine without blocking the current execution. Within the context of a coroutine, it can be used to perform background tasks without blocking the main thread. In the first example, launch is used to check for internet connection in the background. |
Suspend Functions | Suspended functions are a core component of coroutines in Kotlin. They allow the execution of long-running or blocking tasks asynchronously without blocking threads. They are used in conjunction with coroutines to perform network or I/O operations asynchronously. In the second example, suspended functions are used to perform insert and delete operations in the database, as well as to make network calls via Retrofit. |
Strategy | Description |
---|---|
Async-await | Async-await functions are a crucial part of modern programming languages because they enable asynchronous concurrency. This is really useful for us, developers, to write code that can efficiently manage time-consuming and non-blocking operations. In the context of Flutter, these functions are used to handle tasks such as network requests, repetitive tasks in the background, complex calculations, and other operations that may take time to complete. To make the Hive application always responsive and non-blocking, we use a lot of async-await operations to manage time-consuming tasks, such as saving data to local storage, retrieving data from local storage, making login and sign-up requests, and handling time conversions. |
Future | Future is really useful in Flutter because it handles asynchronous operations that take time to complete without blocking the main thread. In our implementation, we decided to use Future to declare lists of events, which retrieve the information of the events from local storage to show in the different views when the user does not have connectivity. This implementation is done three times: in the feed view to know all the available events, and in the Calendar view, which has a Future list to load the events from local storage that will occur in the future and those that have occurred in the past. |