Deferred Value Design Pattern
Explore the Deferred Value design pattern in Kotlin to manage asynchronous computations. Learn how to use CompletableDeferred to return future results, handle success or exceptions with complete and completeExceptionally, and control execution with await and cancel methods. This lesson helps you understand combining the Proxy and State patterns to write efficient concurrent Kotlin code.
We'll cover the following...
The goal of the Deferred Value design pattern is to return a reference to a result of an asynchronous computation. A Future in Java and Scala, and a Promise in JavaScript are both implementations of the Deferred Value design pattern.
Interestingly enough, the Deferred Value itself is an implementation of both the Proxy design pattern and the State design pattern. ...