Releases: Kotlin/kotlinx.coroutines
Releases · Kotlin/kotlinx.coroutines
0.21.2
- Fixed
openSubscriptionextension for reactivePublisher/Observable/Flowablewhen used withselect { ... }and added an optionalrequestparameter to specify how many elements are requested from publisher in advance on subscription (see #197). - Simplified implementation of
Channel.flatMapusingtoChannelfunction to work around Android 5.0 APK install SIGSEGV (see #205).
0.21.1
- Improved performance of coroutine dispatching (
DispatchTaskinstance is no longer allocated). - Fixed
Job.cancelandCompletableDeferred.completeto support cancelling/completing states and properly wait for their children to complete on join/await (see #199). - Fixed a bug in binary heap implementation (used internally by
delay) which could have resulted in wrong delay time in rare circumstances. - Coroutines library for Kotlin/JS:
Promise.asDeferredimmediately installs handlers to avoid "Unhandled promise rejection" warning.- Use
window.postMessageinstead ofsetTimeoutfor coroutines inside the browser to avoid timeout throttling (see #194). - Use custom queue in
Window.awaitAnimationFrameto align all animations and reduce overhead. - Introduced
Window.asCoroutineDispatcher()extension function.
JS
- Migrated to Kotlin 1.2.10.
- Coroutines library for Kotlin/JS and multiplatform projects (see #33):
launchandasynccoroutine builders.JobandDeferredlight-weight future with cancellation support.delayandyieldtop-level suspending functions.awaitextension for JSPromiseandasPromise/asDeferredconversions.promisecoroutine builder.Job()andCompletableDeferred()factories.- Full support for parent-child coroutine hierarchies.
Window.awaitAnimationFrameextension function.- Sample frontend Kotlin/JS application with coroutine-driven animations.
runis deprecated and renamed towithContext(see #134).runBlockingandEventLoopimplementations optimized (see #190).
0.20
- Migrated to Kotlin 1.2.0.
- Channels:
- Sequence-like
filter,map, etc extensions onReceiveChannelare introduced (see #88 by @fvasco and #69 by @konrad-kaminski). - Introduced
ReceiveChannel.cancelmethod. - All operators on
ReceiveChannelfully consume the original channel (cancelit when they are done) using a helperconsumeextension. - Deprecated
ActorJobandProducerJob;actornow returnsSendChannelandproducereturnsReceiveChannel(see #127). SendChannel.sendBlockingextension method (see #157 by @fvasco).
- Sequence-like
- Parent-child relations between coroutines:
- Introduced an optional
parentjob parameter for all coroutine builders so that code with an explict parentJobis more natural. - Added
parentparameter toCompletableDeferredconstructor. - Introduced
Job.childrenproperty. Job.cancelChildrenis now an extension (member is deprecated and hidden).Job.joinChildrenextension is introduced.- Deprecated
Job.attachChildas a error-prone API. - Fixed StackOverflow when waiting for a lot of completed children that did not remove their handlers from the parent.
- Introduced an optional
- Use
java.util.ServiceLoaderto find default instances ofCoroutineExceptionHandler. - Android UI integration:
- Added missing
DefaultDispatcheron some reactive operators (see #174 by @fvasco) - Fixed
actorandproduceso that a cancellation of a Job cancels the underlying channel (closes and removes all the pending messages). - Fixed sporadic failure of
example-context-06(see #160) - Fixed hang of
Job.starton lazy coroutine with attachedinvokeOnCompletionhandler. - A more gradual introduction to
runBlockingand coroutines in the guide (see #166).
0.19.3
0.19.2
- Fixed
ArrayBroadcastChannelreceive of stale elements onopenSubscription. Only elements that are sent after invocation ofopenSubscriptionare received now. - Added a default value for
contextparameter torxFlowable(see PR #146 by @PhilGlass). - Exception propagation logic from cancelled coroutines is adjusted (see #152):
- When cancelled coroutine crashes due to some other exception, this other exception becomes the cancellation reason of the coroutine, while the original cancellation reason is suppressed.
UnexpectedCoroutineExceptionis no longer used to report those cases as is removed.- This fixes a race between crash of CPU-consuming coroutine and cancellation which resulted in an unhandled exception and lead to crashes on Android.
runuses cancelling state & propagates exceptions when cancelled (see #147):- When coroutine that was switched into a different dispatcher using
runis cancelled, the run invocation does not complete immediately, but waits until the body completes. - If the body completes with exception, then this exception is propagated.
- When coroutine that was switched into a different dispatcher using
- No
JobinnewSingleThreadContextandnewFixedThreadPoolContextanymore (see #149, #151):- This resolves the common issue of using
run(ctx)where ctx comes from eithernewSingleThreadContextornewFixedThreadPoolContextinvocation. They both used to return a combination of dispatcher + job, and this job was overriding the parent job, thus preventing propagation of cancellation. Not anymore. ThreadPoolDispatcherclass is now public and is the result type for both functions. It has theclosemethod to release the thread pool.
- This resolves the common issue of using
0.19.1
- Failed parent Job cancels all children jobs, then waits for them them. This makes parent-child hierarchies easier to get working right without having to use
try/catchor other exception handlers. - Fixed a race in
ArrayBroadcastChannelbetweensendandopenChannelinvocations (see #138). - Fixed quite a rare race in
runBlockingthat resulted inAssertionError. Unfortunately, cannot write a reliable stress-test to reproduce it. - Updated Reactor support to leverage Bismuth release train (contributed by @sdeleuze, see PR #141)
0.19
- This release is published to Maven Central.
DefaultDispatcheris introduced (see #136):launch,async,produce,actorand other integration-specific coroutine builders now use
DefaultDispatcheras the default value for theircontextparameter.- When a context is explicitly specified,
newCoroutineContextfunction checks if there is any
interceptor/dispatcher defined in the context and usesDefaultDispatcherif there is none. DefaultDispatcheris currently defined to be equal toCommonPool.- Examples in the guide now start with
launch { ... }code and explanation on the nature
and the need for coroutine context starts in "Coroutine context and dispatchers" section.
- Parent coroutines now wait for their children (see #125):
- Job completing state is introduced in documentation as a state in which parent coroutine waits for its children.
Job.attachChildandJob.cancelChildrenare introduced.Job.joinnow always checks cancellation status of invoker coroutine for predictable behavior when joining
failed child coroutine.Job.cancelAndJoinextension is introduced.CoroutineContext.cancelandCoroutineContext.cancelChildrenextensions are introduced for convenience.withTimeout/withTimeoutOrNullblocks become proper coroutines that haveCoroutineScopeand wait for children, too.- Diagnostics in cancellation and unexpected exception messages are improved,
coroutine name is included in debug mode. - Fixed cancellable suspending functions to throw
CancellationException(as was documented before) even when
the coroutine is cancelled with another application-specific exception. JobCancellationExceptionis introduced as a specific subclass ofCancellationExceptionwhich is
used for coroutines that are cancelled without cause and to wrap application-specific exceptions.Job.getCompletionExceptionis renamed toJob.getCancellationExceptionand return a wrapper exception if needed.- Introduced
Deferred.getCompletionExceptionOrNullto get not-wrapped exception result ofasynctask. - Updated docs for
Job&Deferredto explain parent/child relations.
selectexpression is modularized:SelectClause(0,1,2)interfaces are introduced, so that synchronization
constructs can define their select clauses without having to modify
the source of theSelectBuilderinkotlinx-corounes-coremodule.Job.onJoin,Deferred.onAwait,Mutex.onLock,SendChannel.onSend,ReceiveChannel.onReceive, etc
that were functions before are now properties returning the corresponding select clauses. Old functions
are left in bytecode for backwards compatibility on use-site, but any outside code that was implementing those
interfaces by itself must be updated.- This opens road to moving channels into a separate module in future updates.
- Renamed
TimeoutExceptiontoTimeoutCancellationException(old name is deprecated). - Fixed various minor problems:
kotlinx-coroutines-iomodule is introduced. It is a work-in-progress onByteReadChannelandByteWriteChannel
interfaces, their implementations, and related classes to enable convenient coroutine integration with various
asynchronous I/O libraries and sockets. It is currently unstable and will change in the next release.
0.18
- Kotlin 1.1.4 is required to use this version, which enables:
withLockandconsumeEachfunctions are now inline suspend functions.JobSupportclass implementation is optimized (one fewer field).
TimeoutExceptionis public (see #89).- Improvements to
Mutex(courtesy of @fvasco): - Fixed NPE when
ArrayBroadcastChannelis closed concurrently with receive (see #97). - Fixed bug in internal class LockFreeLinkedList that resulted in ISE under stress in extremely rare circumstances.
- Integrations:
- quasar: Introduced integration with suspendable JVM functions
that are instrumented with Parallel Universe Quasar
(thanks to the help of @pron). - reactor: Replaced deprecated
setCancellationwithonDiposeand
updated to Aluminium-SR3 release (courtesy of @yxf07, see #96) - jdk8: Added adapters for
java.timeclasses (courtesy of @fvasco, see #93)
- quasar: Introduced integration with suspendable JVM functions
0.17
CompletableDeferredis introduced as a set-once event-like communication primitive (see #70).- Coroutines guide uses it in a section on actors.
CompletableDeferredis an interface with private impl (courtesy of @fvasco, see #86).- It extends
Deferredinterface withcompleteandcompleteExceptionallyfunctions.
Job.joinandDeferred.awaitwait until a cancelled coroutine stops execution (see #64).JobandDeferredhave a new cancelling state which they enter on invocation ofcancel.Job.invokeOnCompletionhas an additional overload withonCancelling: Booleanparameter to install handlers that are fired as soon as coroutine enters cancelling state as opposed to waiting until it completes.- Internal
selectimplementation is refactored to decouple it fromJobSupportinternal class and to optimize its state-machine. - Internal
AbstractCoroutineclass is refactored so that it is extended only by true coroutines, all of which support the new cancelling state.
CoroutineScope.contextis renamed tocoroutineContextto avoid conflicts with other usages ofcontextin applications (like Android context, see #75).BroadcastChannel.openis renamed toopenSubscription(see #54).- Fixed
StackOverflowErrorin a convoy ofMutex.unlockinvokers withUnconfineddispatcher (see #80). - Fixed
SecurityExceptionwhen trying to use coroutines library with installedSecurityManager. - Fixed a bug in
withTimeoutOrNullin case with nested timeouts when coroutine was cancelled before it was ever suspended. - Fixed a minor problem with
awaitFirston reactive streams that would have resulted in spurious stack-traces printed on the console when used with publishers/observables that continue to invokeonNextdespite being cancelled/disposed (which they are technically allowed to do by specification). - All factory functions for various interfaces are implemented as top-level functions (affects
Job,Channel,BroadcastChannel,Mutex,EventLoop, andCoroutineExceptionHandler). Previous approach of usingoperator invokeon their companion objects is deprecated. - Nicer-to-use debug
toStringimplementations for coroutine dispatcher tasks and continuations. - A default dispatcher for
delayis rewritten and now shares code withEventLoopImplthat is used byrunBlocking. It internally supports non-defaultTimeSourceso that delay-using tests can be written with "virtual time" by replacing their time source for the duration of tests (this feature is not available outside of the library).