Future
The spawn expression returns a Future<T> type, where T is the return type of the lambda expression. Calling the get() method blocks the current thread until the target thread finishes execution and returns the result.
Future<T> supports three ways to retrieve results: get() waits indefinitely, get(timeout: Duration) waits with a timeout, and tryGet() is a non-blocking attempt. If the thread throws an exception during execution, get() will rethrow that exception.
The example on the right splits the task of summing 1 to 100 into two parts, computing them in parallel across two threads. The main thread collects the computation results from both threads using left.get() and right.get().