Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Kotlin Coroutine

Buzzvil
December 19, 2018
270

Kotlin Coroutine

Buzzvil

December 19, 2018
Tweet

Transcript

  1. Coroutine - Cheaper than thread [Explore01Thread] - a new way

    of managing background threads that can simplify code by reducing the need for callbacks. - Coroutines are a Kotlin feature that convert async callbacks for long-running tasks, such as database or network access, into sequential code.
  2. - Parallel Stream Structure of [functional] sequential code is the

    same as parallel code - Coroutine Structure of [Imperative] synchronous code is the same as asynchronous code
  3. Parallel vs Asynchronous - Where we are in JVM -

    Node was a huge paradigm shift. And it’s real power when it comes to scale - Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.
  4. Let’s examine parallel just a bit, in java - Parallel

    Stream [test1Stream] Structure of [functional] sequential code is the same as parallel code
  5. Why not be happy with that? - Sequential code and

    parallel code structure was so different
  6. Blocking to non-blocking -16ms - 16ms * 60 frames =

    960 ms O - 17ms * 60 frames = 1020ms X - 60 pages per second is ideal, as most people see this as high-quality, smooth motion.
  7. Using suspend While it's suspended waiting for a result, it

    unblocks the thread that it's running on so other functions or coroutines can run.
  8. Doing asyn - [Explore05HttpAsync] - Deferred - Kotlin has a

    method Deferred.await() that is used to wait for the result from a coroutine started with the async builder.
  9. Reference - KotlinConf 2018 - Exploring Coroutines in Kotlin by

    Venkat Subramariam - How to Kotlin - from the Lead Kotlin Language Designer (Google I/O '18) - Android coroutine example - Converting existing callback APIs with coroutines - Testing coroutines Code: https://github.com/realwind2048/kotlinCoroutine