サクサク読めて、アプリ限定の機能も多数!
トップへ戻る
画力アップ
elizarov.medium.com
Photo by John Mark Arnold on UnsplashWhat are Kotlin Exceptions and how should you use them? To figure it out let’s look at their origins first. Exceptions came to Kotlin from Java. The story with exceptions in Java is complicated, though. I’ll give a brief overview. The OriginJava has a unique concept of checked exceptions that were designed to solve the problem of verbose and error-prone error-h
Photo by Darron BirgenheierReactive Extensions¹ (ReactiveX or Rx for short) were initially created by Erik Meijer for .NET and were revealed to the public in 2010. It was a new approach to API for asynchronous data streams that generalized observer pattern with callbacks for emitted elements (onNext), stream completion (onCompleted), and error (onError), and introduced stream-processing operators
But what happens if the collector is also slow and adds its own 100 ms delay before printing each element? Check it out: It takes around 2 seconds to complete, because both emitter and collector are parts of a sequential execution here and it alternates between them: Concurrent coroutinesCan we structure this execution so that the whole operation completes faster, changing neither emitter’s nor co
Flow by Grant TarrantIn a previous “Cold flows, hot channels” story¹ I’ve defined cold and hot data streams and shown a use-case for Kotlin Flows — cold asynchronous streams. Now let us peek under the hood, examine their design, and see how a combination of language features and a library enables a powerful abstraction with simple design. A Flow in Kotlin is represented by an interface²: interface
Markus Trienke, Sunset over drift iceAsynchronous, long-running, or remote operations can be expressed using a future type, so a function returning a Value could be implemented as: fun fooAsync(p: Params): CompletableFuture<Value> = CompletableFuture.supplyAsync { bar(p) } When you callfooAsync(p) you get a promise to deliver a value in the future and there is an operation bar running in backgroun
In a basic object-oriented programming you can directly call only methods of a class that were defined by the authors of this class. This is fine for user-defined classes. Moreover, 20–30 years ago, before the advent of massive code-reuse in the form of very large standard libraries and open-source, most of your code would have been working with classes from your own code anyway — with code mainta
I’ve been programming in Java for a long, long time. I’ve learned what it takes to write and maintain big (as in million-lines of code) software in Java and I’ve witnessed industry-wide struggle to avoid and contain the dreaded NullPointerException (NPE) that seemed to plague any reasonably-sized Java codebase. This realization of the danger of the null reference had dawned on the industry way bef
Structured concurrency in Kotlin Coroutines requires developers to always launch coroutines in the context of CoroutineScope or to specify a scope explicitly. It seems that using GlobalScope is a good default for launching work in background, however we do not recommend using GlobalScope. Why? Let us see it with an example. Suppose that we have some CPU-consuming or IO-bound blocking task which ta
Modern operating systems support multiple threads in each process. Thread is an abstraction that gives the illusion of a separate CPU core that executes your code, but you can start as many threads as you need, regardless of the number of physical cores your CPU actually has. So with multiple threads, you should not be worried that some of your threads are blocked, should you? Not so fast. There a
Today marks the release of a version 0.26.0 of kotlinx.coroutines library and an introduction of structured concurrency to Kotlin coroutines. It is more than just a feature — it marks an ideology shift so big that I’m writing this post to explain it. Since the initial rollout of Kotlin coroutines as an experimental feature in Kotlin 1.1 in the beginning of 2017 we’ve been working hard to explain t
このページを最初にブックマークしてみませんか?
『elizarov.medium.com』の新着エントリーを見る
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く