What is Kotlin Coroutines?

Video overview of experimental part of interesting programming language
07 August 2017   1179
Kotlin

Statically-typed programming language that runs on the Java Virtual Machine and also can be compiled to JavaScript source code

Some APIs initiate long-running operations (such as network IO, file IO, CPU- or GPU-intensive work, etc) and require the caller to block until they complete. Coroutines provide a way to avoid blocking a thread and replace it with a cheaper and more controllable operation: suspension of a coroutine.

Coroutines simplify asynchronous programming by putting the complications into libraries. The logic of the program can be expressed sequentially in a coroutine, and the underlying library will figure out the asynchrony for us. The library can wrap relevant parts of the user code into callbacks, subscribe to relevant events, schedule execution on different threads (or even different machines!), and the code remains as simple as if it was sequentially executed.

Many asynchronous mechanisms available in other languages can be implemented as libraries using Kotlin coroutines. This includes async/await from C# and ECMAScript, channels and select from Go, and generators/yield from C# and Python. 

In this report, Roman Elizarov talks about Kotlin Corouties.  Coroutines that are presented in Kotlin 1.1 in a massively redesigned form versus the original plan. This talk assumes familiarity with previous year's presentation (only a short overview is given) and focuses on challenges that were encountered during the implementation of the original vision on Kotlin coroutines.

Roman is tutor developer at JetBrains and ITMO university.

JetBrains to Roll Out Ktor Framework

Framework is suitable for writing back-end projects and microservices in the Kotlin language
20 November 2018   185

JetBrains developers told about the release of the stable version of the Ktor 1.0 framework. It helps to create asynchronous servers and clients in related systems. According to the creators, the framework is suitable for writing back-end projects and microservices in the Kotlin language. Documentation and project generator are published on the official website.

First of all, it is worth noting that this is an open source project that is distributed under the Apache 2 license. The main components are:

  • HTTP server running on a virtual machine. It works on Netty, Jetty, and server-side Java programs. It can be placed in a container, embedded in desktop or Android applications, as well as run on Tomcat. Moreover, it corresponds to the paradigm of the application of twelve factors.
  • Multiplatform HTTP client. Although asynchronous, it uses the same coroutines and I / O elements that control the server.

Tools will help the developer to customize the main components of the application.

The Kotlin / Native project supports Ktor, starting with version 0.8. In this case, the working version of Kotlin / Native 0.9 was released in early September 2018. In it, developers added support for unsigned types and interoperability with C, Objective-C / Swift.