1# Change log for kotlinx.coroutines 2 3## Version 1.3.1 4 5This is a minor update with various fixes: 6* Flow: Fix recursion in combineTransform<T1, T2, R> (#1466). 7* Fixed race in the Semaphore (#1477). 8* Repaired some of ListenableFuture.kt's cancellation corner cases (#1441). 9* Consistently unwrap exception in slow path of CompletionStage.asDeferred (#1479). 10* Various fixes in documentation (#1496, #1476, #1470, #1468). 11* Various cleanups and additions in tests. 12 13Note: Kotlin/Native artifacts are now published with Gradle metadata format version 1.0, so you will need 14Gradle version 5.3 or later to use this version of kotlinx.coroutines in your Kotlin/Native project. 15 16## Version 1.3.0 17 18### Flow 19 20This version is the first stable release with [`Flow`](https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html) API. 21 22All `Flow` API not marked with `@FlowPreview` or `@ExperimentalCoroutinesApi` annotations are stable and here to stay. 23Flow declarations marked with `@ExperimentalCoroutinesApi` have [the same guarantees](/docs/compatibility.md#experimental-api) as regular experimental API. 24Please note that API marked with `@FlowPreview` have [weak guarantees](/docs/compatibility.md#flow-preview-api) on source, binary and semantic compatibility. 25 26### Changelog 27 28* A new [guide section](/docs/flow.md) about Flow. 29* `CoroutineDispatcher.asExecutor` extension (#1450). 30* Fixed bug when `select` statement could report the same exception twice (#1433). 31* Fixed context preservation in `flatMapMerge` in a case when collected values were immediately emitted to another flow (#1440). 32* Reactive Flow integrations enclosing files are renamed for better interoperability with Java. 33* Default buffer size in all Flow operators is increased to 64. 34* Kotlin updated to 1.3.50. 35 36## Version 1.3.0-RC2 37 38### Flow improvements 39* Operators for UI programming are reworked for the sake of consistency, naming scheme for operator overloads is introduced: 40 * `combineLatest` is deprecated in the favor of `combine`. 41 * `combineTransform` operator for non-trivial transformations (#1224). 42 * Top-level `combine` and `combineTransform` overloads for multiple flows (#1262). 43 * `switchMap` is deprecated. `flatMapLatest`, `mapLatest` and `transformLatest` are introduced instead (#1335). 44 * `collectLatest` terminal operator (#1269). 45 46* Improved cancellation support in `flattenMerge` (#1392). 47* `channelFlow` cancellation does not leak to the parent (#1334). 48* Fixed flow invariant enforcement for `suspend fun main` (#1421). 49* `delayEach` and `delayFlow` are deprecated (#1429). 50 51### General changes 52* Integration with Reactor context 53 * Propagation of the coroutine context of `await` calls into Mono/Flux builder. 54 * Publisher.asFlow propagates coroutine context from `collect` call to the Publisher. 55 * New `Flow.asFlux ` builder. 56 57* ServiceLoader-code is adjusted to avoid I/O on the Main thread on newer (3.6.0+) Android toolchain. 58* Stacktrace recovery support for minified builds on Android (#1416). 59* Guava version in `kotlinx-coroutines-guava` updated to `28.0`. 60* `setTimeout`-based JS dispatcher for platforms where `process` is unavailable (#1404). 61* Native, JS and common modules are added to `kotlinx-coroutines-bom`. 62* Fixed bug with ignored `acquiredPermits` in `Semaphore` (#1423). 63 64## Version 1.3.0-RC 65 66### Flow 67 68* Core `Flow` API is promoted to stable 69* New basic `Flow` operators: `withIndex`, `collectIndexed`, `distinctUntilChanged` overload 70* New core `Flow` operators: `onStart` and `onCompletion` 71* `ReceiveChannel.consumeAsFlow` and `emitAll` (#1340) 72 73### General changes 74 75* Kotlin updated to 1.3.41 76* Added `kotlinx-coroutines-bom` with Maven Bill of Materials (#1110) 77* Reactive integrations are seriously improved 78 * All builders now are top-level functions instead of extensions on `CoroutineScope` and prohibit `Job` instance in their context to simplify lifecycle management 79 * Fatal exceptions are handled consistently (#1297) 80 * Integration with Reactor Context added (#284) 81* Stacktrace recovery for `suspend fun main` (#1328) 82* `CoroutineScope.cancel` extension with message (#1338) 83* Protection against non-monotonic clocks in `delay` (#1312) 84* `Duration.ZERO` is handled properly in JDK 8 extensions (#1349) 85* Library code is adjusted to be more minification-friendly 86 87## Version 1.3.0-M2 88 89 * Kotlin updated to 1.3.40. 90 * `Flow` exception transparency concept. 91 * New declarative `Flow` operators: `onCompletion`, `catch`, `retryWhen`, `launchIn`. `onError*` operators are deprecated in favour of `catch`. (#1263) 92 * `Publisher.asFlow` is integrated with `buffer` operator. 93 * `Publisher.openSubscription` default request size is `1` instead of `0` (#1267). 94 95## Version 1.3.0-M1 96 97Flow: 98 * Core `Flow` interfaces and operators are graduated from preview status to experimental. 99 * Context preservation invariant rework (#1210). 100 * `channelFlow` and `callbackFlow` replacements for `flowViaChannel` for concurrent flows or callback-based APIs. 101 * `flow` prohibits emissions from non-scoped coroutines by default and recommends to use `channelFlow` instead to avoid most of the concurrency-related bugs. 102 * Flow cannot be implemented directly 103 * `AbstractFlow` is introduced for extension (e.g. for managing state) and ensures all context preservation invariants. 104 * Buffer size is decoupled from all operators that imply channel usage (#1233) 105 * `buffer` operator can be used to adjust buffer size of any buffer-dependent operator (e.g. `channelFlow`, `flowOn` and `flatMapMerge`). 106 * `conflate` operator is introduced. 107 * Flow performance is significantly improved. 108 * New operators: `scan`, `scanReduce`, `first`, `emitAll`. 109 * `flowWith` and `flowViaChannel` are deprecated. 110 * `retry` ignores cancellation exceptions from upstream when the flow was externally cancelled (#1122). 111 * `combineLatest` overloads for multiple flows (#1193). 112 * Fixed numerical overflow in `drop` operator. 113 114Channels: 115 * `consumeEach` is promoted to experimental API (#1080). 116 * Conflated channels always deliver the latest value after closing (#332, #1235). 117 * Non-suspending `ChannelIterator.next` to improve iteration performance (#1162). 118 * Channel exception types are consistent with `produce` and are no longer swallowed as cancellation exceptions in case of programmatic errors (#957, #1128). 119 * All operators on channels (that were prone to coroutine leaks) are deprecated in the favor of `Flow`. 120 121General changes: 122 * Kotlin updated to 1.3.31 123 * `Semaphore` implementation (#1088) 124 * Loading of `Dispatchers.Main` is tweaked so the latest version of R8 can completely remove I/O when loading it (#1231). 125 * Performace of all JS dispatchers is significantly improved (#820). 126 * `withContext` checks cancellation status on exit to make reasoning about sequential concurrent code easier (#1177). 127 * Consistent exception handling mechanism for complex hierarchies (#689). 128 * Convenient overload for `CoroutinesTimeout.seconds` (#1184). 129 * Fix cancellation bug in onJoin (#1130). 130 * Prevent internal names clash that caused errors for ProGuard (#1159). 131 * POSIX's `nanosleep` as `delay` in `runBlocking ` in K/N (#1225). 132 133## Version 1.2.2 134 135* Kotlin updated to 1.3.40. 136 137## Version 1.2.1 138 139Major: 140 * Infrastructure for testing coroutine-specific code in `kotlinx-coroutines-test`: `runBlockingTest`, `TestCoroutineScope` and `TestCoroutineDispatcher`, contributed by Sean McQuillan (@objcode). Obsolete `TestCoroutineContext` from `kotlinx-coroutines-core` is deprecated. 141 * `Job.asCompletableFuture` extension in jdk8 module (#1113). 142 143Flow improvements: 144 * `flowViaChannel` rework: block parameter is no longer suspending, but provides `CoroutineScope` receiver and allows conflated channel (#1081, #1112). 145 * New operators: `switchMap`, `sample`, `debounce` (#1107). 146 * `consumerEach` is deprecated on `Publisher`, `ObservableSource` and `MaybeSource`, `collect` extension is introduced instead (#1080). 147 148Other: 149 * Race in Job.join and concurrent cancellation is fixed (#1123). 150 * Stacktrace recovery machinery improved: cycle detection works through recovered exceptions, cancellation exceptions are recovered on cancellation fast-path. 151 * Atomicfu-related bug fixes: publish transformed artifacts, do not propagate transitive atomicfu dependency (#1064, #1116). 152 * Publication to NPM fixed (#1118). 153 * Misplaced resources are removed from the final jar (#1131). 154 155## Version 1.2.0 156 157 * Kotlin updated to 1.3.30. 158 * New API: `CancellableContinuation.resume` with `onCancelling` lambda (#1044) to consistently handle closeable resources. 159 * Play services task version updated to 16.0.1. 160 * `ReceiveChannel.isEmpty` is no longer deprecated 161 162A lot of `Flow` improvements: 163 * Purity property is renamed to context preservation and became more restrictive. 164 * `zip` and `combineLatest` operators. 165 * Integration with RxJava2 166 * `flatMap`, `merge` and `concatenate` are replaced with `flattenConcat`, `flattenMerge`, `flatMapConcat` and `flatMapMerge`. 167 * Various documentation improvements and minor bug fixes. 168 169Note that `Flow` **is not** leaving its [preview status](/docs/compatibility.md#flow-preview-api). 170 171## Version 1.2.0-alpha-2 172 173This release contains major [feature preview](/docs/compatibility.md#flow-preview-api): cold streams aka `Flow` (#254). 174 175Performance: 176* Performance of `Dispatcher.Main` initialization is significantly improved (#878). 177 178## Version 1.2.0-alpha 179 180* Major debug agent improvements. Real stacktraces are merged with coroutine stacktraces for running coroutines, merging heuristic is improved, API is cleaned up and is on its road to stabilization (#997). 181* `CoroutineTimeout` rule or JUnit4 is introduced to simplify coroutines debugging (#938). 182* Stacktrace recovery improvements. Exceptions with custom properties are no longer copied, `CopyableThrowable` interface is introduced, machinery is [documented](https://github.com/Kotlin/kotlinx.coroutines/blob/develop/docs/debugging.md) (#921, #950). 183* `Dispatchers.Unconfined`, `MainCoroutineDispatcher.immediate`, `MainScope` and `CoroutineScope.cancel` are promoted to stable API (#972). 184* `CompletableJob` is introduced (#971). 185* Structured concurrency is integrated into futures and listenable futures (#1008). 186* `ensurePresent` and `isPresent` extensions for `ThreadLocal` (#1028). 187* `ensureActive` extensions for `CoroutineContext`, `CoroutineScope` and `Job` (#963). 188* `SendChannel.isFull` and `ReceiveChannel.isEmpty` are deprecated (#1053). 189* `withContext` checks cancellation on entering (#962). 190* Operator `invoke` on `CoroutineDispatcher` (#428). 191* Java 8 extensions for `delay` and `withTimeout` now properly handle too large values (#428). 192* A global exception handler for fatal exceptions in coroutines is introduced (#808, #773). 193* Major improvements in cancellation machinery and exceptions delivery consistency. Cancel with custom exception is completely removed. 194* Kotlin version is updated to 1.3.21. 195* Do not use private API on newer Androids to handle exceptions (#822). 196 197Bug fixes: 198* Proper `select` support in debug agent (#931). 199* Proper `supervisorScope` support in debug agent (#915). 200* Throwing `initCause` does no longer trigger an internal error (#933). 201* Lazy actors are started when calling `close` in order to cleanup their resources (#939). 202* Minor bugs in reactive integrations are fixed (#1008). 203* Experimental scheduler shutdown sequence is fixed (#990). 204 205## Version 1.1.1 206 207* Maintenance release, no changes in the codebase 208* Kotlin is updated to 1.3.20 209* Gradle is updated to 4.10 210* Native module is published with Gradle metadata v0.4 211 212## Version 1.1.0 213 214* Kotlin version updated to 1.3.11. 215* Resumes to `CancellableContinuation` in the final state produce `IllegalStateException` (#901). This change does not affect #830, races between resume and cancellation do not lead to an exceptional situation. 216* `runBlocking` is integrated with `Dispatchers.Unconfined` by sharing an internal event loop. This change does not affect the semantics of the previously correct code but allows to mix multiple `runBlocking` and unconfined tasks (#860). 217 218## Version 1.1.0-alpha 219 220### Major improvements in coroutines testing and debugging 221* New module: [`kotlinx-coroutines-debug`](https://github.com/Kotlin/kotlinx.coroutines/blob/master/core/kotlinx-coroutines-debug/README.md). Debug agent that improves coroutines stacktraces, allows to print all active coroutines and its hierarchies and can be installed as Java agent. 222* New module: [`kotlinx-coroutines-test`](https://github.com/Kotlin/kotlinx.coroutines/blob/master/core/kotlinx-coroutines-test/README.md). Allows setting arbitrary `Dispatchers.Main` implementation for tests (#810). 223* Stacktrace recovery mechanism. Exceptions from coroutines are recovered from current coroutine stacktraces to simplify exception diagnostic. Enabled in debug mode, controlled by `kotlinx.coroutines.debug` system property (#493). 224 225### Other improvements 226* `MainScope` factory and `CoroutineScope.cancel` extension (#829). One line `CoroutineScope` integration! 227* `CancellableContinuation` race between `resumeWithException` and `cancel` is addressed, exceptions during cancellation are no longer reported to exception handler (#830, #892). 228* `Dispatchers.Default` now consumes much less CPU on JVM (#840). 229* Better diagnostic and fast failure if an uninitialized dispatcher is used (#880). 230* Conflated channel becomes linearizable. 231* Fixed inconsistent coroutines state when the result of the coroutine had type `DisposableHandle` (#835). 232* Fixed `JavaFx` initialization bug (#816). 233* `TimeoutCancellationException` is thrown by `withTimeout` instead of `CancellationException` if negative timeout is supplied (#870). 234* Kotlin/Native single-threaded workers support: coroutines can be safely used in multiple independent K/N workers. 235* jsdom support in `Dispatchers.Default` on JS. 236* rxFlowable generic parameter is now restricted with Any. 237* Guava 27 support in `kotlinx-coroutines-guava`. 238* Coroutines are now built with progressive mode. 239* Various fixes in the documentation. 240 241## Version 1.0.1 242 243* Align `publisher` implementation with Reactive TCK. 244* Reimplement `future` coroutine builders on top of `AbstractCoroutine` (#751). 245* Performance optimizations in `Dispatchers.Default` and `Dispatchers.IO`. 246* Use only public API during `JavaFx` instantiation, fixes warnings on Java 9 and build on Java 11 (#463). 247* Updated contract of `CancellableContinuation.resumeWithException` (documentation fix, see #712). 248* Check cancellation on fast-path of all in-place coroutine builders (`withContext`, `coroutineScope`, `supervisorScope`, `withTimeout` and `withTimeoutOrNull`). 249* Add optional prefix to thread names of `ExperimentalCoroutineDispatcher` (#661). 250* Fixed bug when `ExperimentalCoroutineDispatcher` could end up in inconsistent state if `Thread` constructor throws an exception (#748). 251 252## Version 1.0.0 253 254* All Kotlin dependencies updated to 1.3 release version. 255* Fixed potential memory leak in `HandlerDispatcher.scheduleResumeAfterDelay`, thanks @cbeyls. 256* `yield` support for `Unconfined` and immediate dispatchers (#737). 257* Various documentation improvements. 258 259## Version 1.0.0-RC1 260 261* Coroutines API is updated to Kotlin 1.3. 262* Deprecated API is removed or marked as `internal`. 263* Experimental and internal coroutine API is marked with corresponding `kotlin.experimental.Experimental` annotation. If you are using `@ExperimentalCoroutinesApi` or `@InternalCoroutinesApi` you should explicitly opt-in, otherwise compilation warning (or error) will be produced. 264* `Unconfined` dispatcher (and all dispatchers which support immediate invocation) forms event-loop on top of current thread, thus preventing all `StackOverflowError`s. `Unconfined` dispatcher is now much safer for the general use and may leave its experimental status soon (#704). 265* Significantly improved performance of suspending hot loops in `kotlinx.coroutines` (#537). 266* Proguard rules are embedded into coroutines JAR to assist jettifier (#657) 267* Fixed bug in shutdown sequence of `runBlocking` (#692). 268* `ReceiveChannel.receiveOrNull` is marked as obsolete and deprecated. 269* `Job.cancel(cause)` and `ReceiveChannel.cancel(cause)` are deprecated, `cancel()` returns `Unit` (#713). 270 271## Version 0.30.2 272 273* `Dispatchers.Main` is instantiated lazily (see #658 and #665). 274* Blocking coroutine dispatcher views are now shutdown properly (#678). 275* Prevent leaking Kotlin 1.3 from atomicfu dependency (#659). 276* Thread-pool based dispatcher factories are marked as obsolete (#261). 277* Fixed exception loss on `withContext` cancellation (#675). 278 279## Version 0.30.1 280 281Maintenance release: 282* Added `Dispatchers.Main` to common dispatchers, which can be used from Android, Swing and JavaFx projects if a corresponding integration library is added to dependencies. 283* With `Dispatchers.Main` improvement tooling bug in Android Studio #626 is mitigated, so Android users now can safely start the migration to the latest `kotlinx.coroutines` version. 284* Fixed bug with thread unsafety of shutdown sequence in `EventLoop`. 285* Experimental coroutine dispatcher now has `close` contract similar to Java `Executor`, so it can be safely instantiated and closed multiple times (affects only unit tests). 286* Atomicfu version is updated with fixes in JS transformer (see #609) 287 288## Version 0.30.0 289 290* **[Major]** Further improvements in exception handling — no failure exception is lost. 291 * `async` and async-like builders cancel parent on failure (it affects `CompletableDeferred`, and all reactive integration builders). 292 * This makes parallel decomposition exception-safe and reliable without having to rember about `awaitAll` (see #552). 293 * `Job()` wih parent now also cancels parent on failure consistently with other scopes. 294 * All coroutine builders and `Job` implementations propagate failure to the parent unless it is a `CancellationException`. 295 * Note, "scoping" builders don't "cancel the parent" verbatim, but rethrow the corresponding exception to the caller for handling. 296 * `SupervisorJob()` and `supervisorScope { ... }` are introduced, allowing for a flexible implementation of custom exception-handling policies, see a [new section in the guide on supervision](docs/exception-handling.md#supervision). 297 * Got rid of `awaitAll` in documentation and rewrote `currentScope` section (see #624). 298* **[Major]** Coroutine scheduler is used for `Dispatchers.Default` by default instead of deprecated `CommonPool`. 299 * "`DefaultDispatcher`" is used as a public name of the default impl (you'll see it thread names and in the guide). 300 * `-Dkotlinx.coroutines.scheduler=off` can be used to switch back to `CommonPool` for a time being (until deprecated CommonPool is removed). 301* Make `CoroutineStart.ATOMIC` experimental as it covers important use-case with resource cleanup in finally block (see #627). 302* Restored binary compatibility of `Executor.asCoroutineDispatcher` (see #629). 303* Fixed OOM in thread-pool dispatchers (see #571). 304* Check for cancellation when starting coroutine with `Dispatchers.Unconfined` (see #621). 305* A bunch of various performance optimizations and docs fixes, including contributions from @AlexanderPrendota, @PaulWoitaschek. 306 307## Version 0.27.0 308 309* **[Major]** Public API revision. All public API was reviewed and marked as preparation to `1.0` release: 310 1. `@Deprecated` API. All API marked as deprecated will be removed in 1.0 release without replacement. 311 2. `@ExperimentalCoroutinesApi` API. This API is experimental and may change in the future, but migration mechanisms will be provided. Signature, binary compatibility and semantics can be changed. 312 3. `@InternalCoroutinesApi`. This API is intended to be used **only** from within `kotlinx.coroutines`. It can and will be changed, broken 313 and removed in the future releases without any warnings and migration aids. If you find yourself using this API, it is better to report 314 your use-case to Github issues, so decent, stable and well-tested alternative can be provided. 315 4. `@ObsoleteCoroutinesApi`. This API has serious known flaws and will be replaced with a better alternative in the nearest releases. 316 5. Regular public API. This API is proven to be stable and is not going to be changed. If at some point it will be discovered that such API 317 has unfixable design flaws, it will be gradually deprecated with proper replacement and migration aid, but won't be removed for at least a year. 318* **[Major]** Job state machine is reworked. It includes various performance improvements, fixes in 319data-races which could appear in a rare circumstances and consolidation of cancellation and exception handling. 320Visible consequences of include more robust exception handling for large coroutines hierarchies and for different kinds of `CancellationException`, transparent parallel decomposition and consistent view of coroutines hierarchy in terms of its state (see #220 and #585). 321* NIO, Quasar and Rx1 integration modules are removed with no replacement (see #595, #601, #603). 322* `withContext` is now aligned with structured concurrency and awaits for all launched tasks, its performance is significantly improved (see #553 and #617). 323* Added integration module with Play Services Task API. Thanks @SUPERCILEX and @lucasvalenteds for the contribution! 324* Integration with Rx2 now respects nullability in type constraints (see #347). Thanks @Dmitry-Borodin for the contribution! 325* `CompletableFuture.await` and `ListenableFuture.await` now propagate cancellation to the future (see #611). 326* Cancellation of `runBlocking` machinery is improved (see #589). 327* Coroutine guide is restructured and split to multiple files for the sake of simplicity. 328* `CoroutineScope` factory methods add `Job` if it is missing from the context to enforce structured concurrency (see #610). 329* `Handler.asCoroutineDispatcher` has a `name` parameter for better debugging (see #615). 330* Fixed bug when `CoroutineSchedule` was closed from one of its threads (see #612). 331* Exceptions from `CoroutineExceptionHandler` are reported by default exception handler (see #562). 332* `CoroutineName` is now available from common modules (see #570). 333* Update to Kotlin 1.2.70. 334 335## Version 0.26.1 336 337* Android `Main` dispatcher is `async` by default which may significantly improve UI performance. Contributed by @JakeWharton (see #427). 338* Fixed bug when lazily-started coroutine with registered cancellation handler was concurrently started and cancelled. 339* Improved termination sequence in IO dispatcher. 340* Fixed bug with `CoroutineScope.plus` operator (see #559). 341* Various fixes in the documentation. Thanks to @SUPERCILEX, @yorlov, @dualscyther and @soudmaijer! 342 343## Version 0.26.0 344 345* Major rework of `kotlinx.coroutines` concurrency model (see #410 for a full explanation of the rationale behind this change): 346 * All coroutine builders are now extensions on `CoroutineScope` and inherit its `coroutineContext`. Standalone builders are deprecated. 347 * As a consequence, all nested coroutines launched via builders now automatically establish parent-child relationship and inherit `CoroutineDispatcher`. 348 * All coroutine builders use `Dispatchers.Default` by default if `CoroutineInterceptor` is not present in their context. 349 * [CoroutineScope](https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/) became the first-class citizen in `kolinx.coroutines`. 350 * `withContext` `block` argument has `CoroutineScope` as a receiver. 351 * [GlobalScope](https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-global-scope/) is introduced to simplify migration to new API and to launch global-level coroutines. 352 * `currentScope` and `coroutineScope` builders are introduced to extract and provide `CoroutineScope`. 353 * Factory methods to create `CoroutineScope` from `CoroutineContext` are introduced. 354 * `CoroutineScope.isActive` became an extension property. 355 * New sections about structured concurrency in core guide: ["Structured concurrency"](docs/coroutines-guide.md#structured-concurrency), ["Scope builder"](docs/coroutines-guide.md#scope-builder) and ["Structured concurrency with async"](docs/coroutines-guide.md#structured-concurrency-with-async). 356 * New section in UI guide with Android example: ["Structured concurrency, lifecycle and coroutine parent-child hierarchy"](ui/coroutines-guide-ui.md#structured-concurrency,-lifecycle-and-coroutine-parent-child-hierarchy). 357 * Deprecated reactive API is removed. 358* Dispatchers are renamed and grouped in the Dispatchers object (see #41 and #533): 359 * Dispatcher names are consistent. 360 * Old dispatchers including `CommonPool` are deprecated. 361* Fixed bug with JS error in rare cases in `invokeOnCompletion(onCancelling = true)`. 362* Fixed loading of Android exception handler when `Thread.contextClassLoader` is mocked (see #530). 363* Fixed bug when `IO` dispatcher silently hung (see #524 and #525) . 364 365## Version 0.25.3 366 367* Distribution no longer uses multi-version jar which is not supported on Android (see #510). 368* JS version of the library does not depend on AtomicFu anymore: 369 All the atomic boxes in JS are fully erased. 370* Note that versions 0.25.1-2 are skipped for technical reasons (they were not fully released). 371 372## Version 0.25.0 373 374* Major rework on exception-handling and cancellation in coroutines (see #333, #452 and #451): 375 * New ["Exception Handling" section in the guide](docs/coroutines-guide.md#exception-handling) explains exceptions in coroutines. 376 * Semantics of `Job.cancel` resulting `Boolean` value changed — `true` means exception was handled by the job, caller shall handle otherwise. 377 * Exceptions are properly propagated from children to parents. 378 * Installed `CoroutineExceptionHandler` for a family of coroutines receives one aggregated exception in case of failure. 379 * Change `handleCoroutineException` contract, so custom exception handlers can't break coroutines machinery. 380 * Unwrap `JobCancellationException` properly to provide exception transparency over whole call chain. 381* Introduced support for thread-local elements in coroutines context (see #119): 382 * `ThreadContextElement` API for custom thread-context sensitive context elements. 383 * `ThreadLocal.asContextElement()` extension function to convert an arbitrary thread-local into coroutine context element. 384 * New ["Thread-local data" subsection in the guide](docs/coroutines-guide.md#thread-local-data) with examples. 385 * SLF4J Mapped Diagnostic Context (MDC) integration is provided via `MDCContext` element defined in [`kotlinx-coroutines-slf4j`](integration/kotlinx-coroutines-slf4j/README.md) integration module. 386* Introduced IO dispatcher to offload blocking I/O-intensive tasks (see #79). 387* Introduced `ExecutorCoroutineDispatcher` instead of `CloseableCoroutineDispatcher` (see #385). 388* Built with Kotlin 1.2.61 and Kotlin/Native 0.8.2. 389* JAR files for `kotlinx-coroutines` are now [JEP 238](https://openjdk.java.net/jeps/238) multi-release JAR files. 390 * On JDK9+ `VarHandle` is used for atomic operations instead of `Atomic*FieldUpdater` for better performance. 391 * See [AtomicFu](https://github.com/Kotlin/kotlinx.atomicfu/blob/master/README.md) project for details. 392* Reversed addition of `BlockingChecker` extension point to control where `runBlocking` can be used (see #227). 393 * `runBlocking` can be used anywhere without limitations (again), but it would still cause problems if improperly used on UI thread. 394* Corrected return-type of `EventLoop` pseudo-constructor (see #477, PR by @Groostav). 395* Fixed `as*Future()` integration functions to catch all `Throwable` exceptions (see #469). 396* Fixed `runBlocking` cancellation (see #501). 397* Fixed races and timing bugs in `withTimeoutOrNull` (see #498). 398* Execute `EventLoop.invokeOnTimeout` in `DefaultDispatcher` to allow busy-wait loops inside `runBlocking` (see #479). 399* Removed `kotlinx-coroutines-io` module from the project, it has moved to [kotlinx-io](https://github.com/kotlin/kotlinx-io/). 400* Provide experimental API to create limited view of experimental dispatcher (see #475). 401* Various minor fixes by @LouisCAD, @Dmitry-Borodin. 402 403## Version 0.24.0 404 405* Fully multiplatform release with Kotlin/Native support (see #246): 406 * Only single-threaded operation inside `runBlocking` event loop is supported at this moment. 407 * See details on setting up build environment [here](native/README.md). 408* Improved channels: 409 * Introduced `SendChannel.invokeOnClose` (see #341). 410 * Make `close`, `cancel`, `isClosedForSend`, `isClosedForReceive` and `offer` linearizable with other operations (see #359). 411 * Fixed bug when send operation can be stuck in channel forever. 412 * Fixed broadcast channels on JS (see #412). 413* Provides `BlockingChecker` mechanism which checks current context (see #227). 414 * Attempts to use `runBlocking` from any supported UI thread (Android, JavaFx, Swing) will result in exception. 415* Android: 416 * Worked around Android bugs with zero-size ForkJoinPool initialization (see #432, #288). 417 * Introduced `UI.immediate` extension as performance-optimization to immediately execute tasks which are invoked from the UI thread (see #381). 418 * Use it only when absolutely needed. It breaks asynchrony of coroutines and may lead to surprising and unexpected results. 419* Fixed materialization of a `cause` exception for `Job` onCancelling handlers (see #436). 420* Fixed JavaFx `UI` on Java 9 (see #443). 421* Fixed and documented the order between cancellation handlers and continuation resume (see #415). 422* Fixed resumption of cancelled continuation (see #450). 423* Includes multiple fixes to documentation contributed by @paolop, @SahilLone, @rocketraman, @bdavisx, @mtopolnik, @Groostav. 424* Experimental coroutines scheduler preview (JVM only): 425 * Written from scratch and optimized for communicating coroutines. 426 * Performs significantly better than ForkJoinPool on coroutine benchmarks and for connected applications with [ktor](https://ktor.io). 427 * Supports automatic creating of new threads for blocking operations running on the same thread pool (with an eye on solving #79), but there is no stable public API for it just yet. 428 * For preview, run JVM with `-Dkotlinx.coroutines.scheduler` option. In this case `DefaultDispatcher` is set to new experimental scheduler instead of FJP-based `CommonPool`. 429 * Submit your feedback to issue #261. 430 431## Version 0.23.4 432 433* Recompiled with Kotlin 1.2.51 to solve broken metadata problem (see [KT-24944](https://youtrack.jetbrains.com/issue/KT-24944)). 434 435## Version 0.23.3 436 437* Kotlin 1.2.50. 438* JS: Moved to atomicfu version 0.10.3 that properly matches NPM & Kotlin/JS module names (see #396). 439* Improve source-code compatibility with previous (0.22.x) version of `openChannel().use { ... }` pattern by providing deprecated extension function `use` on `ReceiveChannel`. 440 441## Version 0.23.2 442 443* IO: fix joining and continuous writing byte array interference. 444 445## Version 0.23.1 446 447* JS: Fix dependencies in NPM: add "kotlinx-atomicfu" dependency (see #370). 448* Introduce `broadcast` coroutine builder (see #280): 449 * Support `BroadcastChannel.cancel` method to drop the buffer. 450 * Introduce `ReceiveChannel.broadcast()` extension. 451* Fixed a bunch of doc typos (PRs by @paolop). 452* Corrected previous version's release notes (PR by @ansman). 453 454## Version 0.23.0 455 456* Kotlin 1.2.41 457* **Coroutines core module is made mostly cross-platform for JVM and JS**: 458 * Migrate channels and related operators to common, so channels can be used from JS (see #201). 459 * Most of the code is shared between JVM and JS versions using cross-platform version of [AtomicFU](https://github.com/Kotlin/kotlinx.atomicfu) library. 460 * The recent version of Kotlin allows default parameters in common code (see #348). 461 * The project is built using Gradle 4.6. 462* **Breaking change**: `CancellableContinuation` is not a `Job` anymore (see #219): 463 * It does not affect casual users of `suspendCancellableCoroutine`, since all the typically used functions are still there. 464 * `CancellableContinuation.invokeOnCompletion` is deprecated now and its semantics had subtly changed: 465 * `invokeOnCancellation` is a replacement for `invokeOnCompletion` to install a handler. 466 * The handler is **not** invoked on `resume` which corresponds to the typical usage pattern. 467 * There is no need to check for `cont.isCancelled` in a typical handler code anymore (since handler is invoked only when continuation is cancelled). 468 * Multiple cancellation handlers cannot be installed. 469 * Cancellation handlers cannot be removed (disposed of) anymore. 470 * This change is designed to allow better performance of suspending cancellable functions: 471 * Now `CancellableContinuation` implementation has simpler state machine and is implemented more efficiently. 472 * Exception handling in `AbstractContinuation` (that implements `CancellableContinuation`) is now consistent: 473 * Always prefer exception thrown from coroutine as exceptional reason, add cancellation cause as suppressed exception. 474* **Big change**: Deprecate `CoroutineScope.coroutineContext`: 475 * It is replaced with top-level `coroutineContext` function from Kotlin standard library. 476* Improve `ReceiveChannel` operators implementations to guarantee closing of the source channels under all circumstances (see #279): 477 * `onCompletion` parameter added to `produce` and all other coroutine builders. 478 * Introduce `ReceiveChannel.consumes(): CompletionHandler` extension function. 479* Replace `SubscriptionReceiveChannel` with `ReceiveChannel` (see #283, PR by @deva666). 480 * `ReceiveChannel.use` extension is introduced to preserve source compatibility, but is deprecated. 481 * `consume` or `consumeEach` extensions should be used for channels. 482 * When writing operators, `produce(onCompletion=consumes()) { ... }` pattern shall be used (see #279 above). 483* JS: Kotlin is declared as peer dependency (see #339, #340, PR by @ansman). 484* Invoke exception handler for actor on cancellation even when channel was successfully closed, so exceptions thrown by actor are always reported (see #368). 485* Introduce `awaitAll` and `joinAll` for `Deferred` and `Job` lists correspondingly (see #171). 486* Unwrap `CompletionException` exception in `CompletionStage.await` slow-path to provide consistent results (see #375). 487* Add extension to `ExecutorService` to return `CloseableCoroutineDispatcher` (see #278, PR by @deva666). 488* Fail with proper message during build if JDK_16 is not set (see #291, PR by @venkatperi). 489* Allow negative timeouts in `delay`, `withTimeout` and `onTimeout` (see #310). 490* Fix a few bugs (leaks on cancellation) in `delay`: 491 * Invoke `clearTimeout` on cancellation in JSDispatcher. 492 * Remove delayed task on cancellation from internal data structure on JVM. 493* Introduce `ticker` function to create "ticker channels" (see #327): 494 * It provides analogue of RX `Observable.timer` for coroutine channels. 495 * It is currently supported on JVM only. 496* Add a test-helper class `TestCoroutineContext` (see #297, PR by @streetsofboston). 497 * It is currently supported on JVM only. 498 * Ticker channels (#327) are not yet compatible with it. 499* Implement a better way to set `CoroutineContext.DEBUG` value (see #316, PR by @dmytrodanylyk): 500 * Made `CoroutineContext.DEBUG_PROPERTY_NAME` constant public. 501 * Introduce public constants with `"on"`, `"off"`, `"auto"` values. 502* Introduce system property to control `CommonPool` parallelism (see #343): 503 * `CommonPool.DEFAULT_PARALLELISM_PROPERTY_NAME` constant is introduced with a value of "kotlinx.coroutines.default.parallelism". 504* Include package-list files into documentation site (see #290). 505* Fix various typos in docs (PRs by @paolop and @ArtsiomCh). 506 507## Version 0.22.5 508 509* JS: Fixed main file reference in [NPM package](https://www.npmjs.com/package/kotlinx-coroutines-core) 510* Added context argument to `Channel.filterNot` (PR by @jcornaz). 511* Implemented debug `toString` for channels (see #185). 512 513## Version 0.22.4 514 515* JS: Publish to NPM (see #229). 516* JS: Use node-style dispatcher on ReactNative (see #236). 517* [jdk8 integration](integration/kotlinx-coroutines-jdk8/README.md) improvements: 518 * Added conversion from `CompletionStage` to `Deferred` (see #262, PR by @jcornaz). 519 * Use fast path in `CompletionStage.await` and make it cancellable. 520 521## Version 0.22.3 522 523* Fixed `produce` builder to close the channel on completion instead of cancelling it, which lead to lost elements with buffered channels (see #256). 524* Don't use `ForkJoinPool` if there is a `SecurityManager` present to work around JNLP problems (see #216, PR by @NikolayMetchev). 525* JS: Check for undefined `window.addEventListener` when choosing default coroutine dispatcher (see #230, PR by @ScottPierce). 526* Update 3rd party dependencies: 527 * [kotlinx-coroutines-rx1](reactive/kotlinx-coroutines-rx1) to RxJava version `1.3.6`. 528 * [kotlinx-coroutines-rx2](reactive/kotlinx-coroutines-rx2) to RxJava version `2.1.9`. 529 * [kotlinx-coroutines-guava](integration/kotlinx-coroutines-guava) to Guava version `24.0-jre`. 530 531## Version 0.22.2 532 533* Android: Use @Keep annotation on AndroidExceptionPreHandler to fix the problem on Android with minification enabled (see #214). 534* Reactive: Added `awaitFirstOrDefault` and `awaitFirstOrNull` extensions (see #224, PR by @konrad-kaminski). 535* Core: Fixed `withTimeout` and `withTimeoutOrNull` that should not use equals on result (see #212, PR by @konrad-kaminski). 536* Core: Fixed hanged receive from a closed subscription of BroadcastChannel (see #226). 537* IO: fixed error propagation (see https://github.com/ktorio/ktor/issues/301). 538* Include common sources into sources jar file to work around KT-20971. 539* Fixed bugs in documentation due to MPP. 540 541## Version 0.22.1 542 543* Migrated to Kotlin 1.2.21. 544* Improved `actor` builder documentation (see #210) and fixed bugs in rendered documentation due to multiplatform. 545* Fixed `runBlocking` to properly support specified dispatchers (see #209). 546* Fixed data race in `Job` implementation (it was hanging at `LockFreeLinkedList.helpDelete` on certain stress tests). 547* `AbstractCoroutine.onCancellation` is invoked before cancellation handler that is set via `invokeOnCompletion`. 548* Ensure that `launch` handles uncaught exception before another coroutine that uses `join` on it resumes (see #208). 549 550## Version 0.22 551 552* Migrated to Kotlin 1.2.20. 553* Introduced stable public API for `AbstractCoroutine`: 554 * Implements `Job`, `Continuation`, and `CoroutineScope`. 555 * Has overridable `onStart`, `onCancellation`, `onCompleted` and `onCompletedExceptionally` functions. 556 * Reactive integration modules are now implemented using public API only. 557 * Notifies onXXX before all the installed handlers, so `launch` handles uncaught exceptions before "joining" coroutines wakeup (see #208). 558 559## Version 0.21.2 560 561* Fixed `openSubscription` extension for reactive `Publisher`/`Observable`/`Flowable` when used with `select { ... }` and added an optional `request` parameter to specify how many elements are requested from publisher in advance on subscription (see #197). 562* Simplified implementation of `Channel.flatMap` using `toChannel` function to work around Android 5.0 APK install SIGSEGV (see #205). 563 564## Version 0.21.1 565 566* Improved performance of coroutine dispatching (`DispatchTask` instance is no longer allocated). 567* Fixed `Job.cancel` and `CompletableDeferred.complete` to support cancelling/completing states and properly wait for their children to complete on join/await (see #199). 568* Fixed a bug in binary heap implementation (used internally by `delay`) which could have resulted in wrong delay time in rare circumstances. 569* Coroutines library for [Kotlin/JS](js/README.md): 570 * `Promise.asDeferred` immediately installs handlers to avoid "Unhandled promise rejection" warning. 571 * Use `window.postMessage` instead of `setTimeout` for coroutines inside the browser to avoid timeout throttling (see #194). 572 * Use custom queue in `Window.awaitAnimationFrame` to align all animations and reduce overhead. 573 * Introduced `Window.asCoroutineDispatcher()` extension function. 574 575## Version 0.21 576 577* Migrated to Kotlin 1.2.10. 578* Coroutines library for [Kotlin/JS](js/README.md) and [multiplatform projects](https://kotlinlang.org/docs/reference/multiplatform.html) (see #33): 579 * `launch` and `async` coroutine builders. 580 * `Job` and `Deferred` light-weight future with cancellation support. 581 * `delay` and `yield` top-level suspending functions. 582 * `await` extension for JS `Promise` and `asPromise`/`asDeferred` conversions. 583 * `promise` coroutine builder. 584 * `Job()` and `CompletableDeferred()` factories. 585 * Full support for parent-child coroutine hierarchies. 586 * `Window.awaitAnimationFrame` extension function. 587 * [Sample frontend Kotlin/JS application](js/example-frontend-js/README.md) with coroutine-driven animations. 588* `run` is deprecated and renamed to `withContext` (see #134). 589* `runBlocking` and `EventLoop` implementations optimized (see #190). 590 591## Version 0.20 592 593* Migrated to Kotlin 1.2.0. 594* Channels: 595 * Sequence-like `filter`, `map`, etc extensions on `ReceiveChannel` are introduced (see #88 by @fvasco and #69 by @konrad-kaminski). 596 * Introduced `ReceiveChannel.cancel` method. 597 * All operators on `ReceiveChannel` fully consume the original channel (`cancel` it when they are done) using a helper `consume` extension. 598 * Deprecated `ActorJob` and `ProducerJob`; `actor` now returns `SendChannel` and `produce` returns `ReceiveChannel` (see #127). 599 * `SendChannel.sendBlocking` extension method (see #157 by @@fvasco). 600* Parent-child relations between coroutines: 601 * Introduced an optional `parent` job parameter for all coroutine builders so that code with an explict parent `Job` is more natural. 602 * Added `parent` parameter to `CompletableDeferred` constructor. 603 * Introduced `Job.children` property. 604 * `Job.cancelChildren` is now an extension (member is deprecated and hidden). 605 * `Job.joinChildren` extension is introduced. 606 * Deprecated `Job.attachChild` as a error-prone API. 607 * Fixed StackOverflow when waiting for a lot of completed children that did not remove their handlers from the parent. 608* Use `java.util.ServiceLoader` to find default instances of `CoroutineExceptionHandler`. 609* Android UI integration: 610 * Use `Thread.getUncaughtExceptionPreHandler` to make sure that exceptions are logged before crash (see #148). 611 * Introduce `UI.awaitFrame` for animation; added sample coroutine-based animation application for Android [here](ui/kotlinx-coroutines-android/animation-app). 612 * Fixed `delay(Long.MAX_VALUE)` (see #161) 613* Added missing `DefaultDispatcher` on some reactive operators (see #174 by @fvasco) 614* Fixed `actor` and `produce` so that a cancellation of a Job cancels the underlying channel (closes and removes all the pending messages). 615* Fixed sporadic failure of `example-context-06` (see #160) 616* Fixed hang of `Job.start` on lazy coroutine with attached `invokeOnCompletion` handler. 617* A more gradual introduction to `runBlocking` and coroutines in the [guide](docs/coroutines-guide.md) (see #166). 618 619## Version 0.19.3 620 621* Fixed `send`/`openSubscription` race in `ArrayBroadcastChannel`. 622 This race lead to stalled (hanged) `send`/`receive` invocations. 623* Project build has been migrated to Gradle. 624 625## Version 0.19.2 626 627* Fixed `ArrayBroadcastChannel` receive of stale elements on `openSubscription`. 628 Only elements that are sent after invocation of `openSubscription` are received now. 629* Added a default value for `context` parameter to `rxFlowable` (see #146 by @PhilGlass). 630* Exception propagation logic from cancelled coroutines is adjusted (see #152): 631 * When cancelled coroutine crashes due to some other exception, this other exception becomes the cancellation reason 632 of the coroutine, while the original cancellation reason is suppressed. 633 * `UnexpectedCoroutineException` is no longer used to report those cases as is removed. 634 * This fixes a race between crash of CPU-consuming coroutine and cancellation which resulted in an unhandled exception 635 and lead to crashes on Android. 636* `run` uses cancelling state & propagates exceptions when cancelled (see #147): 637 * When coroutine that was switched into a different dispatcher using `run` is cancelled, the run invocation does not 638 complete immediately, but waits until the body completes. 639 * If the body completes with exception, then this exception is propagated. 640* No `Job` in `newSingleThreadContext` and `newFixedThreadPoolContext` anymore (see #149, #151): 641 * This resolves the common issue of using `run(ctx)` where ctx comes from either `newSingleThreadContext` or 642 `newFixedThreadPoolContext` invocation. They both used to return a combination of dispatcher + job, 643 and this job was overriding the parent job, thus preventing propagation of cancellation. Not anymore. 644 * `ThreadPoolDispatcher` class is now public and is the result type for both functions. 645 It has the `close` method to release the thread pool. 646 647## Version 0.19.1 648 649* Failed parent Job cancels all children jobs, then waits for them them. 650 This makes parent-child hierarchies easier to get working right without 651 having to use `try/catch` or other exception handlers. 652* Fixed a race in `ArrayBroadcastChannel` between `send` and `openChannel` invocations 653 (see #138). 654* Fixed quite a rare race in `runBlocking` that resulted in `AssertionError`. 655 Unfortunately, cannot write a reliable stress-test to reproduce it. 656* Updated Reactor support to leverage Bismuth release train 657 (contributed by @sdeleuze, see PR #141) 658 659## Version 0.19 660 661* This release is published to Maven Central. 662* `DefaultDispatcher` is introduced (see #136): 663 * `launch`, `async`, `produce`, `actor` and other integration-specific coroutine builders now use 664 `DefaultDispatcher` as the default value for their `context` parameter. 665 * When a context is explicitly specified, `newCoroutineContext` function checks if there is any 666 interceptor/dispatcher defined in the context and uses `DefaultDispatcher` if there is none. 667 * `DefaultDispatcher` is currently defined to be equal to `CommonPool`. 668 * Examples in the [guide](docs/coroutines-guide.md) now start with `launch { ... }` code and explanation on the nature 669 and the need for coroutine context starts in "Coroutine context and dispatchers" section. 670* Parent coroutines now wait for their children (see #125): 671 * Job _completing_ state is introduced in documentation as a state in which parent coroutine waits for its children. 672 * `Job.attachChild` and `Job.cancelChildren` are introduced. 673 * `Job.join` now always checks cancellation status of invoker coroutine for predictable behavior when joining 674 failed child coroutine. 675 * `Job.cancelAndJoin` extension is introduced. 676 * `CoroutineContext.cancel` and `CoroutineContext.cancelChildren` extensions are introduced for convenience. 677 * `withTimeout`/`withTimeoutOrNull` blocks become proper coroutines that have `CoroutineScope` and wait for children, too. 678 * Diagnostics in cancellation and unexpected exception messages are improved, 679 coroutine name is included in debug mode. 680 * Fixed cancellable suspending functions to throw `CancellationException` (as was documented before) even when 681 the coroutine is cancelled with another application-specific exception. 682 * `JobCancellationException` is introduced as a specific subclass of `CancellationException` which is 683 used for coroutines that are cancelled without cause and to wrap application-specific exceptions. 684 * `Job.getCompletionException` is renamed to `Job.getCancellationException` and return a wrapper exception if needed. 685 * Introduced `Deferred.getCompletionExceptionOrNull` to get not-wrapped exception result of `async` task. 686 * Updated docs for `Job` & `Deferred` to explain parent/child relations. 687* `select` expression is modularized: 688 * `SelectClause(0,1,2)` interfaces are introduced, so that synchronization 689 constructs can define their select clauses without having to modify 690 the source of the `SelectBuilder` in `kotlinx-corounes-core` module. 691 * `Job.onJoin`, `Deferred.onAwait`, `Mutex.onLock`, `SendChannel.onSend`, `ReceiveChannel.onReceive`, etc 692 that were functions before are now properties returning the corresponding select clauses. Old functions 693 are left in bytecode for backwards compatibility on use-site, but any outside code that was implementing those 694 interfaces by itself must be updated. 695 * This opens road to moving channels into a separate module in future updates. 696* Renamed `TimeoutException` to `TimeoutCancellationException` (old name is deprecated). 697* Fixed various minor problems: 698 * JavaFx toolkit is now initialized by `JavaFx` context (see #108). 699 * Fixed lost ACC_STATIC on <clinit> methods (see #116). 700 * Fixed link to source code from documentation (see #129). 701 * Fixed `delay` in arbitrary contexts (see #133). 702* `kotlinx-coroutines-io` module is introduced. It is a work-in-progress on `ByteReadChannel` and `ByteWriteChannel` 703 interfaces, their implementations, and related classes to enable convenient coroutine integration with various 704 asynchronous I/O libraries and sockets. It is currently _unstable_ and **will change** in the next release. 705 706## Version 0.18 707 708* Kotlin 1.1.4 is required to use this version, which enables: 709 * `withLock` and `consumeEach` functions are now inline suspend functions. 710 * `JobSupport` class implementation is optimized (one fewer field). 711* `TimeoutException` is public (see #89). 712* Improvements to `Mutex` (courtesy of @fvasco): 713 * Introduced `holdsLock` (see #92). 714 * Improved documentation on `Mutex` fairness (see #90). 715* Fixed NPE when `ArrayBroadcastChannel` is closed concurrently with receive (see #97). 716* Fixed bug in internal class LockFreeLinkedList that resulted in ISE under stress in extremely rare circumstances. 717* Integrations: 718 * [quasar](integration/kotlinx-coroutines-quasar): Introduced integration with suspendable JVM functions 719 that are instrumented with [Parallel Universe Quasar](https://docs.paralleluniverse.co/quasar/) 720 (thanks to the help of @pron). 721 * [reactor](reactive/kotlinx-coroutines-reactor): Replaced deprecated `setCancellation` with `onDipose` and 722 updated to Aluminium-SR3 release (courtesy of @yxf07, see #96) 723 * [jdk8](integration/kotlinx-coroutines-jdk8): Added adapters for `java.time` classes (courtesy of @fvasco, see #93) 724 725## Version 0.17 726 727* `CompletableDeferred` is introduced as a set-once event-like communication primitive (see #70). 728 * [Coroutines guide](docs/coroutines-guide.md) uses it in a section on actors. 729 * `CompletableDeferred` is an interface with private impl (courtesy of @fvasco, see #86). 730 * It extends `Deferred` interface with `complete` and `completeExceptionally` functions. 731* `Job.join` and `Deferred.await` wait until a cancelled coroutine stops execution (see #64). 732 * `Job` and `Deferred` have a new _cancelling_ state which they enter on invocation of `cancel`. 733 * `Job.invokeOnCompletion` has an additional overload with `onCancelling: Boolean` parameter to 734 install handlers that are fired as soon as coroutine enters _cancelling_ state as opposed 735 to waiting until it _completes_. 736 * Internal `select` implementation is refactored to decouple it from `JobSupport` internal class 737 and to optimize its state-machine. 738 * Internal `AbstractCoroutine` class is refactored so that it is extended only by true coroutines, 739 all of which support the new _cancelling_ state. 740* `CoroutineScope.context` is renamed to `coroutineContext` to avoid conflicts with other usages of `context` 741 in applications (like Android context, see #75). 742* `BroadcastChannel.open` is renamed to `openSubscription` (see #54). 743* Fixed `StackOverflowError` in a convoy of `Mutex.unlock` invokers with `Unconfined` dispatcher (see #80). 744* Fixed `SecurityException` when trying to use coroutines library with installed `SecurityManager`. 745* Fixed a bug in `withTimeoutOrNull` in case with nested timeouts when coroutine was cancelled before it was 746 ever suspended. 747* Fixed a minor problem with `awaitFirst` on reactive streams that would have resulted in spurious stack-traces printed 748 on the console when used with publishers/observables that continue to invoke `onNext` despite being cancelled/disposed 749 (which they are technically allowed to do by specification). 750* All factory functions for various interfaces are implemented as top-level functions 751 (affects `Job`, `Channel`, `BroadcastChannel`, `Mutex`, `EventLoop`, and `CoroutineExceptionHandler`). 752 Previous approach of using `operator invoke` on their companion objects is deprecated. 753* Nicer-to-use debug `toString` implementations for coroutine dispatcher tasks and continuations. 754* A default dispatcher for `delay` is rewritten and now shares code with `EventLoopImpl` that is used by 755 `runBlocking`. It internally supports non-default `TimeSource` so that delay-using tests can be written 756 with "virtual time" by replacing their time source for the duration of tests (this feature is not available 757 outside of the library). 758 759## Version 0.16 760 761* Coroutines that are scheduled for execution are cancellable by default now 762 * `suspendAtomicCancellableCoroutine` function is introduced for funs like 763 `send`/`receive`/`receiveOrNull` that require atomic cancellation 764 (they cannot be cancelled after decision was made) 765 * Coroutines started with default mode using 766 `async`/`launch`/`actor` builders can be cancelled before their execution starts 767 * `CoroutineStart.ATOMIC` is introduced as a start mode to specify that 768 coroutine cannot be cancelled before its execution starts 769 * `run` function is also cancellable in the same way and accepts an optional 770 `CoroutineStart` parameter to change this default. 771* `BroadcastChannel` factory function is introduced 772* `CoroutineExceptionHandler` factory function is introduced by @konrad-kaminski 773* [`integration`](integration) directory is introduced for all 3rd party integration projects 774 * It has [contribution guidelines](integration/README.md#contributing) and contributions from community are welcome 775 * Support for Guava `ListenableFuture` in the new [`kotlinx-coroutines-guava`](integration/kotlinx-coroutines-guava) module 776 * Rx1 Scheduler support by @konrad-kaminski 777* Fixed a number of `Channel` and `BroadcastChannel` implementation bugs related to concurrent 778 send/close/close of channels that lead to hanging send, offer or close operations (see #66). 779 Thanks to @chrisly42 and @cy6erGn0m for finding them. 780* Fixed `withTimeoutOrNull` which was returning `null` on timeout of inner or outer `withTimeout` blocks (see #67). 781 Thanks to @gregschlom for finding the problem. 782* Fixed a bug where `Job` fails to dispose a handler when it is the only handler by @uchuhimo 783 784## Version 0.15 785 786* Switched to Kotlin version 1.1.2 (can still be used with 1.1.0). 787* `CoroutineStart` enum is introduced for `launch`/`async`/`actor` builders: 788 * The usage of `luanch(context, start = false)` is deprecated and is replaced with 789 `launch(context, CoroutineStart.LAZY)` 790 * `CoroutineStart.UNDISPATCHED` is introduced to start coroutine execution immediately in the invoker thread, 791 so that `async(context, CoroutineStart.UNDISPATCHED)` is similar to the behavior of C# `async`. 792 * [Guide to UI programming with coroutines](ui/coroutines-guide-ui.md) mentions the use of it to optimize 793 the start of coroutines from UI threads. 794* Introduced `BroadcastChannel` interface in `kotlinx-coroutines-core` module: 795 * It extends `SendChannel` interface and provides `open` function to create subscriptions. 796 * Subscriptions are represented with `SubscriptionReceiveChannel` interface. 797 * The corresponding `SubscriptionReceiveChannel` interfaces are removed from [reactive](reactive) implementation 798 modules. They use an interface defined in `kotlinx-coroutines-core` module. 799 * `ConflatedBroadcastChannel` implementation is provided for state-observation-like use-cases, where a coroutine or a 800 regular code (in UI, for example) updates the state that subscriber coroutines shall react to. 801 * `ArrayBroadcastChannel` implementation is provided for event-bus-like use-cases, where a sequence of events shall 802 be received by multiple subscribers without any omissions. 803 * [Guide to reactive streams with coroutines](reactive/coroutines-guide-reactive.md) includes 804 "Rx Subject vs BroadcastChannel" section. 805* Pull requests from Konrad Kamiński are merged into reactive stream implementations: 806 * Support for Project Reactor `Mono` and `Flux`. 807 See [`kotlinx-coroutines-reactor`](reactive/kotlinx-coroutines-reactor) module. 808 * Implemented Rx1 `Completable.awaitCompleted`. 809 * Added support for Rx2 `Maybe`. 810* Better timeout support: 811 * Introduced `withTimeoutOrNull` function. 812 * Implemented `onTimeout` clause for `select` expressions. 813 * Fixed spurious concurrency inside `withTimeout` blocks on their cancellation. 814 * Changed behavior of `withTimeout` when `CancellationException` is suppressed inside the block. 815 Invocation of `withTimeout` now always returns the result of execution of its inner block. 816* The `channel` property in `ActorScope` is promoted to a wider `Channel` type, so that an actor 817 can have an easy access to its own inbox send channel. 818* Renamed `Mutex.withMutex` to `Mutex.withLock`, old name is deprecated. 819 820## Version 0.14 821 822* Switched to Kotlin version 1.1.1 (can still be used with 1.1.0). 823* Introduced `consumeEach` helper function for channels and reactive streams, Rx 1.x, and Rx 2.x. 824 * It ensures that streams are unsubscribed from on any exception. 825 * Iteration with `for` loop on reactive streams is **deprecated**. 826 * [Guide to reactive streams with coroutines](reactive/coroutines-guide-reactive.md) is updated virtually 827 all over the place to reflect these important changes. 828* Implemented `awaitFirstOrDefault` extension for reactive streams, Rx 1.x, and Rx 2.x. 829* Added `Mutex.withMutex` helper function. 830* `kotlinx-coroutines-android` module has `provided` dependency on of Android APIs to 831 eliminate warnings when using it in android project. 832 833## Version 0.13 834 835* New `kotlinx-coroutinex-android` module with Android `UI` context implementation. 836* Introduced `whileSelect` convenience function. 837* Implemented `ConflatedChannel`. 838* Renamed various `toXXX` conversion functions to `asXXX` (old names are deprecated). 839* `run` is optimized with fast-path case and no longer has `CoroutineScope` in its block. 840* Fixed dispatching logic of `withTimeout` (removed extra dispatch). 841* `EventLoop` that is used by `runBlocking` now implements Delay, giving more predictable test behavior. 842* Various refactorings related to resource management and timeouts: 843 * `Job.Registration` is renamed to `DisposableHandle`. 844 * `EmptyRegistration` is renamed to `NonDisposableHandle`. 845 * `Job.unregisterOnCompletion` is renamed to `Job.disposeOnCompletion`. 846 * `Delay.invokeOnTimeout` is introduced. 847 * `withTimeout` now uses `Delay.invokeOnTimeout` when available. 848* A number of improvement for reactive streams and Rx: 849 * Introduced `rxFlowable` builder for Rx 2.x. 850 * `Scheduler.asCoroutineDispatcher` extension for Rx 2.x. 851 * Fixed bug with sometimes missing `onComplete` in `publish`, `rxObservable`, and `rxFlowable` builders. 852 * Channels that are open for reactive streams are now `Closeable`. 853 * Fixed `CompletableSource.await` and added test for it. 854 * Removed `rx.Completable.await` due to name conflict. 855* New documentation: 856 * [Guide to UI programming with coroutines](ui/coroutines-guide-ui.md) 857 * [Guide to reactive streams with coroutines](reactive/coroutines-guide-reactive.md) 858* Code is published to JCenter repository. 859 860## Version 0.12 861 862* Switched to Kotlin version 1.1.0 release. 863* Reworked and updated utilities for 864 [Reactive Streams](kotlinx-coroutines-reactive), 865 [Rx 1.x](kotlinx-coroutines-rx1), and 866 [Rx 2.x](kotlinx-coroutines-rx2) with library-specific 867 coroutine builders, suspending functions, converters and iteration support. 868* `LinkedListChannel` with unlimited buffer (`offer` always succeeds). 869* `onLock` select clause and an optional `owner` parameter in all `Mutex` functions. 870* `selectUnbiased` function. 871* `actor` coroutine builder. 872* Couple more examples for "Shared mutable state and concurrency" section and 873 "Channels are fair" section with ping-pong table example 874 in [coroutines guide](docs/coroutines-guide.md). 875 876## Version 0.11-rc 877 878* `select` expression with onJoin/onAwait/onSend/onReceive clauses. 879* `Mutex` is moved to `kotlinx.coroutines.sync` package. 880* `ClosedSendChannelException` is a subclass of `CancellationException` now. 881* New sections on "Shared mutable state and concurrency" and "Select expression" 882 in [coroutines guide](docs/coroutines-guide.md). 883 884## Version 0.10-rc 885 886* Switched to Kotlin version 1.1.0-rc-91. 887* `Mutex` synchronization primitive is introduced. 888* `buildChannel` is renamed to `produce`, old name is deprecated. 889* `Job.onCompletion` is renamed to `Job.invokeOnCompletion`, old name is deprecated. 890* `delay` implementation in Swing, JavaFx, and scheduled executors is fixed to avoid an extra dispatch. 891* `CancellableContinuation.resumeUndispatched` is introduced to make this efficient implementation possible. 892* Remove unnecessary creation of `CancellationException` to improve performance, plus other performance improvements. 893* Suppress deprecated and internal APIs from docs. 894* Better docs at top level with categorized summary of classes and functions. 895 896## Version 0.8-beta 897 898* `defer` coroutine builder is renamed to `async`. 899* `lazyDefer` is deprecated, `async` has an optional `start` parameter instead. 900* `LazyDeferred` interface is deprecated, lazy start functionality is integrated into `Job` interface. 901* `launch` has an optional `start` parameter for lazily started coroutines. 902* `Job.start` and `Job.isCompleted` are introduced. 903* `Deferred.isCompletedExceptionally` and `Deferred.isCancelled` are introduced. 904* `Job.getInactiveCancellationException` is renamed to `getCompletionException`. 905* `Job.join` is now a member function. 906* Internal `JobSupport` state machine is enhanced to support _new_ (not-started-yet) state. 907 So, lazy coroutines do not need a separate state variable to track their started/not-started (new/active) status. 908* Exception transparency in `Job.cancel` (original cause is rethrown). 909* Clarified possible states for `Job`/`CancellableContinuation`/`Deferred` in docs. 910* Example on async-style functions and links to API reference site from [coroutines guide](docs/coroutines-guide.md). 911 912## Version 0.7-beta 913 914* Buffered and unbuffered channels are introduced: `Channel`, `SendChannel`, and `ReceiveChannel` interfaces, 915 `RendezvousChannel` and `ArrayChannel` implementations, `Channel()` factory function and `buildChannel{}` 916 coroutines builder. 917* `Here` context is renamed to `Unconfined` (the old name is deprecated). 918* A [guide on coroutines](docs/coroutines-guide.md) is expanded: sections on contexts and channels. 919 920## Version 0.6-beta 921 922* Switched to Kotlin version 1.1.0-beta-37. 923* A [guide on coroutines](docs/coroutines-guide.md) is expanded. 924 925## Version 0.5-beta 926 927* Switched to Kotlin version 1.1.0-beta-22 (republished version). 928* Removed `currentCoroutineContext` and related thread-locals without replacement. 929 Explicitly pass coroutine context around if needed. 930* `lazyDefer(context) {...}` coroutine builder and `LazyDeferred` interface are introduced. 931* The default behaviour of all coroutine dispatchers is changed to always schedule execution of new coroutine 932 for later in this thread or thread pool. Correspondingly, `CoroutineDispatcher.isDispatchNeeded` function 933 has a default implementation that returns `true`. 934* `NonCancellable` context is introduced. 935* Performance optimizations for cancellable continuations (fewer objects created). 936* A [guide on coroutines](docs/coroutines-guide.md) is added. 937 938## Version 0.4-beta 939 940* Switched to Kotlin version 1.1.0-beta-18 (republished version). 941* `CoroutineDispatcher` methods now have `context` parameter. 942* Introduced `CancellableContinuation.isCancelled` 943* Introduced `EventLoop` dispatcher and made it a default for `runBlocking { ... }` 944* Introduced `CoroutineScope` interface with `isActive` and `context` properties; 945 standard coroutine builders include it as receiver for convenience. 946* Introduced `Executor.toCoroutineDispatcher()` extension. 947* Delay scheduler thread is not daemon anymore, but times out automatically. 948* Debugging facilities in `newCoroutineContext` can be explicitly disabled with `-Dkotlinx.coroutines.debug=off`. 949* xxx-test files are renamed to xxx-example for clarity. 950* Fixed NPE in Job implementation when starting coroutine with already cancelled parent job. 951* Support cancellation in `kotlinx-coroutines-nio` module 952