Follow me on Twitter: https://twitter.com/heyitsmohit
Writing a Kotlin Compiler plugin is an uncharted area. The API is undocumented thus far. You may not know where to start. Enter Arrow Meta. It is a library that provides a functional API to write compiler plugins. In this article, I will show you how to write and test a simple compiler plugin with Arrow Meta.
Three years ago, a friend of mine Kevin Most gave a talk at Kotlin Conf on writing compiler plugins. He demonstrated the process with an example plugin DebugLog. I worked on writing an Arrow Meta implementation of this plugin debuglog-meta-arrow. …
Follow me on Twitter: www.twitter.com/heyitsmohit
In February, I gave a presentation at the NY Android Meetup on unit testing Channels and Flows with practical use cases. In this blog post, I will share with you how to test delays, retries, and errors with Flows. I’ve also added useful tips and things to watch out for when unit testing.
Before, we could write unit tests. We need a use case. Suppose we are building a feature in an app that displays user details. We may have a setup as shown below.
Follow me on Twitter https://twitter.com/heyitsmohit
How do we combine emissions from multiple Flows? We could use operators such as zip, flattenMerge and combine. This article will explore how to use the combine operator and how it works under the hood. Interestingly, it uses an experimental construct called a Select expression. We will look at how the select expressions work and how they are used internally in the combine operator.
Let’s start with a simple example of combing two streams together.
How do we assert items are being emitted from a Flow? We could use collect, single, toList extensions on a Flow. But, I found a nice pattern used in the SQL Delight library for Flow assertions. In this article, I will describe how this pattern works.
Let’s look at a simple example we could write a test for. The snippet below shows a repository that takes in an API service. The
getUserDetails method uses the service to make a request to get
UserDetails. The data is returned in a Flow. The example doesn’t have to be implemented with a Flow. …
The Kotlin coroutine library provides a construct called a Channel which behaves like a BlockingQueue. How do Channels work underneath the hood? That’s what we’ll explore in this blog series. As you create complex use cases, it will involve building producers with Channels. Understanding how Channels work will help you to debug your code. Let’s dive into Channels.
What is a Channel?
A Channel is a construct that allows you to send and receive values. It has an optional buffer to cache the values.
In this article, I will explore how to implement and test polling with Channels and Flow. Prior to reading on, please check out this article for understanding the basics of coroutines.
Suppose we would like to hit an endpoint every second and gather the data to display it in the UI. This use case fits many contexts such as continuously updating a live feed or updating scores for a sports event. How could we go about implementing this?
The approach we could take is to create a poller that launches a coroutine that delays for a second, makes an API request and returns the data in a hot Flow. We want the polling to start only when there is a subscriber. …
For the past couple of months, I’ve been battle-testing coroutines in simple and complex uses cases in our app and our open-source SDK. These use cases are bridging our callback-based SDK to coroutines, uploading videos, polling in our player, and interacting with our internal RxJava-based libraries.
In this blog series, I want to share with you how I went about integrating coroutines with these use cases and talk about some of the challenges I encountered. Part 1 of the series, which you’re reading right now, explores how to use coroutines in the simplest use case of making an API request.