`Day23` - Lesson6 ◦ Rough OS recap ▪︎ ...
# 100daysofkotlin-2021
j
Day23
• Lesson6 ◦ Rough OS recap ▪︎ Scheduler takes account of priorities, makes sure all the threads get to run and finish. Dispatcher sets up threads, specifies context ▪︎ (Android) _Main thread(_a.k.a. UI thread) handles UI updates. Calls click handlers & other UI, lifecycle callbacks ▪︎ Blocked process waits for some event / Non-blocking - not blocking the main thread / Examples of “Long” tasks - fetching data from internet, reading a large file, writing to database ▪︎ Asynchronous process runs independently from the main execution steps ◦ Callbacks ▪︎ When task completes, the callback supplied as an argument is called to inform the result to the main thread ▪︎ (Con) Readability, Seems sequential but actually asynchronous. Have to pass errors via another exception handler (result object) ◦ Coroutines ▪︎ Convert callback based code to sequential code. Coroutines can signal errors ▪︎ Asynchronous, Non-blocking, Use suspend functions to make asynchronous code sequential ▪︎ Blocked thread without coroutines - no other work happens / Suspended thread with coroutines - other work can happen until the result is available ▪︎ Jobs are used to cancel coroutine. ▪︎ Dispatcher sends off coroutines to run on various threads (Dispatcher.main, Dispatcher.io) ▪︎ Scopes combine information to define the context in which the coroutine runs. • Did not understand Coroutine just by the lecture, so had some googling time. (1)
Self-Comment
• Whoa.. coroutines are difficult🥺 Should look more into it tomorrow.
Goals Tomorrow
• Finish lesson6, understand coroutines. Think I’ll have to view lesson6 again then.