question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New Sample: Using Kotlin coroutines

See original GitHub issue

I’d like to create a sample that demonstrates the power and elegance of Kotlin coroutines. It will use MVVM, Data Binding and Architecture Components (ViewModel and possibly LiveData). I plan to branch it off dev-todo-mvvm-live-kotlin. The suggested new branch name is dev-todo-mvvm-live-kotlin-coroutines.

The primary objective is to select and consistently apply a small subset of essential Kotlin coroutine idioms.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:10
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
alex-chiviliovcommented, Jan 31, 2018

Hi @dmytrodanylyk

  1. I DISAGREE as it will lead to “leaking abstraction”. The Repository knows what it is doing and what kind of Dispatcher is required to do its work efficiently (CPU bound, I/O bound, long running, etc.). This knowledge should not be leaking to the ViewModel. I AGREE that hard-coding the Dispatcher is not ideal. The better option would be to inject it via the constructor, as we do with ViewModels.

  2. There are no Job cancellations in this project. The reason is:

  • The project is based on MVVM where the ViewModel does not hold any direct references to the View. The ViewModel just exposes Observable properties. The View watches these properties in accordance with its lifecycle. There is no harm continuing the background operation and delivering the result to the ViewModel even after the View has been destroyed. ViewModel properties will be updated when the operation is complete. If the View is still watching, the UI will be updated. If nobody’s watching nothing will happen - no leaks, no crashes.

This is very different from MVP where the Presenter holds a reference to the View, so job cancellations become an important mechanism to avoid lifecycle related leaks and crashes.

0reactions
alex-chiviliovcommented, Feb 13, 2018

@JoseAlcerreca @florina-muntenescu This Kotlin coroutine variant of dev-todo-mvvm-live-kotlin is COMPLETE. Could you please take a look? https://github.com/outware/android-architecture/tree/dev-todo-mvvm-live-kotlin-coroutines

I’ve noticed that the base app has been modified to use Room. Should this change be retrofitted into this variant as well?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Coroutines basics - Kotlin
A coroutine is an instance of suspendable computation. It is conceptually similar to a thread, in the sense that it takes a block...
Read more >
Kotlin Coroutines in Android - ProAndroidDev
The simplest way to create a coroutine is by calling the launch builder on a specified scope. It Launches a new coroutine without...
Read more >
Introduction to Kotlin Coroutines - Baeldung
In this article, we'll be looking at coroutines from the Kotlin language. Simply put, coroutines allow us to create asynchronous programs in ......
Read more >
domnikl/kotlin-coroutine-examples - GitHub
Kotlin coroutine examples. It attempts to explain various use-cases around coroutines in simple terms to explain them. concurrency: run multiple coroutines ...
Read more >
Mastering Kotlin Coroutines - Amit Shekhar
The exact definition of Coroutines: A framework to manage concurrency in a more performant and simple way with its lightweight thread which is ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found