On the third week of my bootcamp at Flatiron School, my buddies and I were presented with a task to create our own CLI (Command Line Interface) app, with some general . We were put into pairs and one…
Asynchronous programming in Android can be done in various ways. Two of them are:
1. Using callback
2. Using coroutines
Below is the example of using callback:
Below is the example of using coroutine:
…
Note that suspend function can only be called either from a coroutine or from another suspend function.
Here GlobalScope implements CoroutineScope and launch is a coroutine builder which is an extension function of CoroutineScope.
Coroutine
A coroutine is an instance of suspendable computation. It is conceptually similar to a thread, in the sense that it takes a block of code to run that works concurrently with the rest of the code. However, a coroutine is not bound to any particular thread. It may suspend its execution in one thread and resume in another one.
Coroutines can be thought of as light-weight threads
// Sequentially executes doWorld followed by “Hello”
// Concurrently executes both sections
suspend fun doWorld() = coroutineScope { // this: CoroutineScope
Coroutine builder: launch, async => to use suspend function in normal function. Used to link normal function and suspending function.
Scoping function: coroutineScope, withContext
The world had come to a standstill. And like everyone else trying to keep their sanity, I tried to keep mine by doing what I had always done — weightlifting. But that old repetitive action now felt…
There are many effective remedies to brighten dull skin, and the fastest ones often involve using natural ingredients that can be found in your kitchen or local grocery store. By following these…
Could you leave it to the experts? The right-wingers and red necks Some have the brains of beetles Or the Tyrannosaurus Rex. Are they little Johnny’s progeny? Or the fruit from Bishop’s loins…