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

Breaking up with RxJava (Kotlin Coroutines & Ch...

Breaking up with RxJava (Kotlin Coroutines & Channels)

Held on 26th June 2018 Kotlin Zagreb Meetup:
https://www.meetup.com/Kotlin-Zagreb/events/251748671/

When RxJava came along, it made our lives so easy that most Android developers jumped ship.
Soon, it was everywhere and everything was a stream. But was that really a good idea?
Now that we have Kotlin, a lot of painpoints solved by (ab)using RxJava are solvable by using plain Kotlin (well, experimental) coroutines.
So should we be jumping ship again? What makes Kotlin a better solution for most of your problems?
In this talk we’ll take a dive into some of Kotlin’s coroutine features and find out how, when and why to say “No” to RxJava.

Ian Rumac

June 28, 2018
Tweet

More Decks by Ian Rumac

Other Decks in Programming

Transcript

  1. What RxJava gives us:
 The Good Parts • Easy stream

    manipulation • Simple concurrency • Chained operators • Observing state changes • Combining operators
  2. What RxJava gives us:
 The Good Parts • Easy stream

    manipulation • Simple concurrency • Chained operators • Observing state changes • Combining operators
  3. • One library that spans across all layers
 (remember migrating?)

    • One library which you shape your code around • One paradigm you force everything into • One naming style • One extra layer of complexity • Code • Mental What RxJava gives us:
 The Bad Parts
  4. • One library that spans across all layers
 (remember migrating?)

    • One library which you shape your code around • One paradigm you force everything into • One naming style • One extra layer of complexity • Code • Mental What RxJava gives us:
 The Bad Parts
  5. • Is your business logic wrapped in Rx? • Is

    your business logic a stream? 
 (not a stream of one ) • Why do you represent the core logic of your app with a stream if it isn’t one? The core
  6. Replacing the operator magic • Collection extensions already in stdlib

    • Easy to write your own • Receiver lambdas
  7. Replacing the operator magic • Collection extensions already in stdlib

    • Easy to write your own • Receiver lambdas
  8. Replacing the operator magic • Collection extensions already in stdlib

    • Easy to write your own • Receiver lambdas
  9. Replacing the operator magic • Collection extensions already in stdlib

    • Easy to write your own • Receiver lambdas
  10. Channels 101 • A hot asynchronous stream of elements •

    Rendezvous transfer • Suspending • Once it’s consumed, it’s consumed
  11. Channels 101 • A hot asynchronous stream of elements •

    Rendezvous transfer • Suspending • Once it’s consumed, it’s consumed • 1 item at a time
  12. Channels of all shapes and sizes! • ArrayChannel - Buffered!

    • ConflatedChannel - Only the latest element • Ticker channel - Time based operations • BroadcastChannel & ArrayBroadcastChannel “Broadcast channel is a non-blocking primitive for communication between the sender and multiple receivers that subscribe for the elements using [open] function and unsubscribe using [SubscriptionReceiveChannel.close] function.” ReceiveChannel<T>
  13. …that’s all nice, but how do I test it? Just

    like any other code. (Context = Unconfined)
  14. Thinking about dumping your old library? • KotlinX Coroutines Rx

    1&2 • Kotlin Coroutine (Experimental) Retrofit Adapter • Still experimental! • Wrap the boilerplate