Kotlin Coroutines by Tutorial: Mastering Coroutines in Kotlin and Android

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Learn Coroutines in Kotlin and Android!

Executing background tasks has always been a big challenge in every environment and, in particular, on mobile devices where resources are limited. Kotlin has simplified the way you can write code improving your productivity with a new programming paradigm, enhancing object-oriented and functional programming with with simple, powerful and new constructs. Coroutines are one of these!

Who This Book Is For

This book is for intermediate Kotlin or Android developers who already know the basics of UI development but want to learn coroutine API in order to simplify and optimize their code.

Topics Covered in This Book

  • Asynchronous programming: Learn what asynchronous programming means and how to achieve it using not blocking calls.
  • Configuration: Learn how to configure IntelliJ and Android Studio in order to use Coroutine APIs.
  • Coroutine principles**: Learn what coroutines and launching builders are and how to manage Job dependencies.
  • Suspending functions: This is the main concept around coroutines and you'll learn how to declare a suspending function and how to deal with results.
  • Sequences and Iterators: Learn how to manage theoretically infinite collections of data in an efficient way using Sequences, Iterators and the yield function.
  • Thread communication techniques**: Learn how different tasks can communicate using Channels, Actors, and specific coroutine operators.
  • And much more, including benchmarks, Broadcast Channels, State machines!
  • One thing you can count on: After reading this book, you’ll be prepared to take advantage of all the improvements coroutines have to offer!

    About the Tutorial Team

    The Tutorial Team is a group of app developers and authors who write tutorials at the popular website raywenderlich.com. We take pride in making sure each tutorial we write holds to the highest standards of quality. We want our tutorials to be well written, easy to follow, and fun. If you've enjoyed the tutorials we've written in the past, you're in for a treat. The tutorials we've written for this book are some of our best yet - and this book contains detailed technical knowledge you simply won't be able to find anywhere else.

    Author(s): raywenderlich Tutorial Team, Filip Babić, Nishant Srivastava
    Edition: 2
    Publisher: Razeware LLC
    Year: 2019

    Language: English
    Pages: 352
    Tags: Kotlin, Coroutines

    What You Need
    Book License
    Book Source Code & Forums
    Book Updates
    About the Cover
    Introduction
    About Kotlin
    About Coroutines
    How to read this book
    Chapter 1: What Is Asynchronous Programming?
    Providing feedback
    Why multithreading?
    Interacting with the UI thread from the background
    Handling work completion using callbacks
    Indentation hell
    Using reactive extensions for background work
    Diving deeper into the complexity of Rx
    A blast from the past
    Explaining coroutines: The inner works
    Variations through history
    Key points
    Where to go from here?
    Chapter 2: Setting Up Your Build Environments
    Choosing the build environments
    Installing the IntelliJ IDEA
    Building the Android environment
    Importing a project
    Key points
    Where to go from here?
    Chapter 3: Getting Started with Coroutines
    Executing routines
    Launching a coroutine
    Building coroutines
    Explaining jobs
    Canceling Jobs
    Digging deeper into coroutines
    Posting to the UI thread
    Key points
    Where to go from here?
    Chapter 4: Suspending Functions
    Suspending vs. non-suspending
    Elaborating continuations
    Creating your own suspendable API
    Key points
    Where to go from here?
    Chapter 5: Async/Await
    The async/await pattern
    Learning from the past
    Using async/await
    Deferring values
    Combining multiple deferred values
    Being cooperative and structured
    Key points
    Where to go from here?
    Chapter 6: Coroutine Context
    Contextualizing coroutines
    Providing contexts
    Key points
    Chapter 7: Coroutine Contexts & Dispatchers
    Work scheduling
    Coroutine dispatcher types
    Using dispatchers
    Key points
    Chapter 8: Exception Handling
    Exception propagation
    Handling exceptions
    Callback wrapping
    Key points
    Where to go from here?
    Chapter 9: Manage Cancellation
    Cancelling a coroutine
    Key points
    Where to go from here?
    Chapter 10: Building Sequences & Iterators with Yield
    Getting started with sequences
    Enter: Sequence
    Generators and Sequences
    SequenceScope is here to stay
    Yield and YieldAll at your service
    Key points
    Where to go from here?
    Chapter 11: Channels
    Getting started with channels
    Pipelines
    Buffered channel
    Comparing send and offer
    Comparing receive and poll
    Error handling
    Comparing Channels to Java Queues
    Key points
    Chapter 12: Broadcast Channels
    Getting started with broadcast channels
    ConflatedBroadcast channel
    ReactiveX vs. BroadcastChannel
    Key points
    Where to go from here?
    Chapter 13: Producer & Actors
    Producing and consuming data
    Producer-consumer problem
    Acting upon data
    Key points
    Where to go from here?
    Chapter 14: Beginning with Coroutines Flow
    Streams of data
    Limitations of streams
    A new approach to streams
    Flow Constraints
    Key Points
    Chapter 15: Testing Coroutines
    Getting started
    Writing tests for Coroutines
    Setting up the test environment
    Summing it up
    Key points
    Chapter 16: Android Concurrency Before Coroutines
    Getting started
    Does Android need coroutines?
    Coroutines
    Introducing Anko
    Key points
    Where to go from here?
    Chapter 17: Coroutines on Android - Part 1
    Getting started
    What’s in the context?
    Converting existing API call to use coroutines
    Coroutines and Android lifecycle
    Key points
    Where to go from here?
    Chapter 18: Coroutines on Android - Part 2
    Getting started
    Debugging coroutines
    Exception handling
    Don’t forget testing
    Anko: Simplified coroutines
    Key points
    Conclusion