aboutsummaryrefslogtreecommitdiff
path: root/reactive
AgeCommit message (Collapse)Author
2021-03-25Introduce trySend and tryReceive channel operations as a future replacement ↵Vsevolod Tolstopyatov
for error-prone offer, poll and receiveOrNull Fixes #974
2021-03-23Simplify internal coroutines machinery (#2512)Vsevolod Tolstopyatov
* Merge onStartInternal and onStart to reduce the number of methods and make code a bit simpler * Rework initParentJob * Always establish a parent-child relationship when creating a subclass of AbstractCoroutine. That's our own internal class that we have full control of and it never has a chance to leak to the user-code (so cancellation handlers will be installed etc.). Force implementors of AbstractCoroutine deliberately choose whether parent-child relationship should be established * As a consequence, get rid of parentContext in all our coroutine classes that are not ScopeCoroutine * Remove some dead code * Get rid of an additional parent field from ScopeCoroutine Leverage already presented information in our implementation, just expose it via an already present internal interface
2021-03-09Replace deprecated '*compile' configurations. (#2574)Yahor Berdnikau
They were deprecated long time ago and were removed in Gradle 7
2021-02-04Update copyright year (#2520)Vsevolod Tolstopyatov
2020-12-28bump reactor-core to 3.4.x version and replace deprecated API usage (#2458)Mikhael Sokolov
2020-11-30Update Knit to 0.2.3 (#2415)Vsevolod Tolstopyatov
2020-10-26Update experimental declarations (#2316)Vsevolod Tolstopyatov
* Gracefully increase deprecation level on Channel operators instead of removing them, a warning was not strict enough * Remove hidden onCompletion from -M release * Promote StateFlow and SharedFlow to stable API * Lift out experimentality where it is applicable * CoroutineDispatcher.invoke * ReceiveChannel.consume and ReceiveChannel.consumeEach * Flow core operators: onStart, onCompletion, onEmpty * CompletableDeferred.completeWith * awaitCancellation * Add experimentality notes where applicable
2020-10-23Fix potential crash in Rx2 and Rx3 asFlow extension (#2333)Vsevolod Tolstopyatov
Fixes #2104 Fixes #2299 Co-authored-by: Louis CAD <louis.cognault@gmail.com>
2020-10-13Introduce SharedFlow and sharing operators (#2069)Roman Elizarov
* Introduce SharedFlow and sharing operators Summary of changes: * SharedFlow, MutableSharedFlow and its constructor. * StateFlow implements SharedFlow. * SharedFlow.onSubscription operator, clarified docs in other onXxx operators. * BufferOverflow strategy in kotlinx.coroutines.channels package. * shareIn and stateIn operators and SharingStarted strategies for them. * SharedFlow.flowOn error lint (up from StateFlow). * Precise cancellable() operator fusion. * Precise distinctUntilChanged() operator fusion. * StateFlow.compareAndSet function. * asStateFlow and asSharedFlow read-only view functions. * Consistently clarified docs on cold vs hot flows. * Future deprecation notice for BroadcastChannel, ConflatedBroadcastChannel, broadcast, and broadcastIn. * Channel(...) constructor function has onBufferOverflow parameter. * buffer(...) operator has onBufferOverflow parameter. * shareIn/stateIn buffer and overflow strategy are configured via upstream buffer operators. * shareIn/stateIn fuse with upstream flowOn for more efficient execution. * conflate() is implemented as buffer(onBufferOverflow=KEEP_LATEST), non-suspending strategies are reasonably supported with 0 and default capacities. * Added reactive operator migration hints. * WhileSubscribed with kotlin.time.Duration params Fixes #2034 Fixes #2047 Co-authored-by: Ibraheem Zaman <1zaman@users.noreply.github.com> Co-authored-by: Thomas Vos <thomasjsvos@gmail.com> Co-authored-by: Travis Wyatt <travis.i.wyatt@gmail.com>
2020-10-12Breaking: Get rid of atomic cancellation and provide a replacement (#1937)Roman Elizarov
This is a problematic for Android when Main dispatcher is cancelled on destroyed activity. Atomic nature of channels is designed to prevent loss of elements, which is really not an issue for a typical application, but creates problem when used with channels. * Internal suspendAtomicCancellableCoroutine -> suspendCancellableCoroutine * Internal suspendAtomicCancellableCoroutineReusable -> suspendCancellableCoroutineReusable * Remove atomic cancellation from docs * Ensures that flowOn does not resume downstream after cancellation. * MODE_ATOMIC_DEFAULT renamed into MODE_ATOMIC * Introduced MODE_CANCELLABLE_REUSABLE to track suspendCancellableCoroutineReusable * Better documentation for MODE_XXX constants. * Added stress test for proper handling of MODE_CANCELLABLE_REUSABLE and fixed test for #1123 bug with job.join (working in MODE_CANCELLABLE) that was not properly failing in the absence of the proper code in CancellableContinuationImpl.getResult * Added test for Flow.combine that should be fixed * Support extended invokeOnCancellation contract * Introduced internal tryResumeAtomic * Channel onUnderliveredElement is introduced as a replacement. Fixes #1265 Fixes #1813 Fixes #1915 Fixes #1936 Co-authored-by: Louis CAD <louis.cognault@gmail.com> Co-authored-by: Vsevolod Tolstopyatov <qwwdfsad@gmail.com>
2020-10-09Cancel current Job on RejectedExecutionException (#2012)Roman Elizarov
When the Executor that was used with Executor.asCoroutineDispatcher() extension rejects the submitted task, it means that it had reached its capacity and so the executing current Job should be canceled to terminate it as soon as possible. This way RejectedExecutionException works as a rate-limiter just like it serves this purpose in executor-based Java code. Fixes #2003
2020-10-08Provide asFlowable and asObservable by their names in binary instead … (#2285)Vsevolod Tolstopyatov
* Provide asFlowable and asObservable by their names in binary instead of 'from' function to prevent naming clash for Java users. * Do not provide @JvmOverloads for convenience of Java interop * Deprecate ReceiveChannel.asObservable by the way Fixes #2182
2020-10-05Kts transition (#2261)Vsevolod Tolstopyatov
* Kotlin DSL - 'reactive:reactor' * Kotlin DSL - 'reactive:jdk9' * Kotlin DSL - 'kotlinx-coroutines-slf4j' * Kotlin DSL - 'kotlinx-coroutines-guava' * Plugin repo management in 'pluginManagement' block * Remove redundant stdlib dependencies (#2253) Co-authored-by: Victor Turansky <victor.turansky@gmail.com>
2020-09-22Add Publisher.awaitSingleOrDefault|Null|Else extensions (#2260)Sébastien Deleuze
This commit adds awaitSingle variants similar to awaitFirst ones, but always emitting the value during onComplete(). Fixes #1993
2020-08-25Transition to the Gradle ktsVictor Turansky
Non-deprecated 'jmhJar' configuration (#2032) (+9 squashed commits) Squashed commits: [8d07d3695] Use new Kotlin/JS plugin (#1983) * Use new Kotlin/JS plugin * Support legacy DCE mode for 1.4-M2 [d22464030] Add Dokka configuration method [56e1c9bfe] Dokka plugin in 'buildSrc' [dfdd202e6] Remove unused repositories [4cf1d02dc] Kotlin DSL - 'javafx' [d8f7d507e] Avoid task name duplication [f06a56b8b] Avoid task name duplication [a09df3de5] Separate 'UnpackAar' action [fd5bf6b9c] Separate 'RunR8' task
2020-08-10Support context in Flow.asPublisher and similar methods (#2156)Roman Elizarov
Fixes #2155 Co-authored-by: Vsevolod Tolstopyatov <qwwdfsad@gmail.com>
2020-07-16Fix race in Flow.asPublisher (#2124)Roman Elizarov
The race was leading to emitting more items via onNext than requested, the corresponding stress-test was added, too Fixes #2109
2020-07-03Fix typos in docs (#2098)Yanis Batura
Co-authored-by: Louis CAD <louis.cognault@gmail.com>
2020-05-18Flow cancellation (#2028)Vsevolod Tolstopyatov
Make Flow more cancellation friendly: * flow builder is cancellable by default * New unambiguous currentCoroutineContext top-level function * New Flow.cancellable() operator Fixes #2026
2020-05-02'reactor_vesion' -> 'reactor_veRsion' (#1976)Victor Turansky
2020-04-29Kts transition (#1951)Vsevolod Tolstopyatov
* Kotlin DSL - 'android:example-app' (#1940) * 'android:example-app'. Gradle 5.6.1 - sync with root project * Kotlin DSL - 'android:example-app' * Kotlin DSL - 'android:animation-app' (#1941) * 'android:animation-app'. Gradle 5.6.1 - sync with root project * Kotlin DSL - 'android:animation-app' * Kotlin DSL - 'swing' (#1943) * Kotlin DSL - 'integration:jdk8' (#1944) * Kotlin DSL - 'test' (#1945) * Kotlin DSL - 'reactive:reactive' (#1946) * Kotlin DSL - 'android-unit-tests' * Use relative paths * Kotlin DSL - 'js-stub' (#1938) (#1959) * Kotlin DSL - 'android' (#1938) (#1956) * Kotlin DSL - 'stdlib-stubs' (#1938) (#1955) * Kotlin DSL - 'site' (#1938) (#1954) * Kotlin DSL - 'maven-central' (#1938) (#1953) * Kotlin DSL - 'benchmarks' (#1938) (#1952) Co-authored-by: Victor Turansky <victor.turansky@gmail.com>
2020-04-24Integration with RxJava3 (#1950)Vsevolod Tolstopyatov
Fixes #1883 Co-authored-by: Zac Sweers <zsweers@slack-corp.com>
2020-03-27Enable strict explicit mode (#1877)Vsevolod Tolstopyatov
2020-03-13JDK9 Flow integration (#1783)dkhalanskyjb
JDK9 Flow integration is implemented as thin wrappers around the Reactive Streams integration.
2020-03-06Make call to service loader in reactor integrations optimizable by R8 (#1847)Vsevolod Tolstopyatov
Fixes #1817
2020-03-04Reuse RxJava built-in disposed Disposable (#1841)Vsevolod Tolstopyatov
2020-03-04Add ObservableSource.asFlow operator (#1768)Marek Langiewicz
2020-02-18Update copyright yearVsevolod Tolstopyatov
2020-02-14Use a separate Knit tool (#1486)Roman Elizarov
* Use a separate Knit tool version 0.1.2 * Hierarchical knit.properties files are introduced which are gathered while walking up the directory tree with the properties in knit resources being top-level ones. * Freemarker templates for "knit.include" (top-level of example files) and "test.template" (test template) are introduced with locations that are resolved from properties. * KNIT and TEST_OUT directives are not supported anymore. - Knitting is controlled by "knit.dir" and "knit.pattern" props. - "test.name" prop or TEST_NAME directive drives test gen. * All markdown files are now clean of top-level knit-related boilerplate (only TEST_NAME directive is remaining in some) * All example files are renumbered. It affects example-basic-xx, which had the legacy numbering with later insertions. * All auto-generated files now have the correct source-file name specified at their beginning, due to consistent use of template substitution. * No need to customize knit.pattern anymore (works out-of-the box) * "knit.name" is automatically generated based on example's file name "example-basic-01" -> "exampleBasic01" * Not match-pattern-group woodoo anymore, "knit.pattern" cannot have any user-defined match groups. * No need to look for "package xxx" in knitted sources, as the example's package is always ${knit.package}.${knit.name} * Simpler test names: testKotlinxCoroutinesGuideBasic01 -> testExampleBasic01 * Replaced END_TOC with END directive * Build-scripts are improved: - Consistent code to use mavenLocal when snapshots versions are used. - Proper substitution logic to use Android AAR files so that Dokka has correct links to Google APIs. - Google repository is added to all projects.
2020-02-13Fix a race in some tests for JavaRX integration (#1801)dkhalanskyjb
An extremely rare race could happen in any of the tests in `LeakedExceptionTest` in the following case: * `withExceptionHandler` runs the block passed to it; * In one of the last iterations of `repeat`, `select` in `combine` happens on both flows at the same time, that is, the block that was passed to `rx[Something]` runs in two threads simultaneously; * One of these two threads (thread A) runs anomalously slow; * The other thread successfully throws an exception; * This exception is propagated to `catch`, so `collect` is finished; * `repeat` is exited, the block passed to `withExceptionHandler` is done executing; * `withExceptionHandler` sets back the usual exception handler, which fails when an exception in JavaRX happens (see https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling); * Thread A wakes up and throws an exception. This time, it is passed not to `handler`, which is made specifically to deal with this, but to the default handler. As a fix, now a special coroutine context passed to `rx[Something]` ensures that the spawned executions are run in a thread pool that blocks until all the tasks are done.
2020-02-11Improve test styleDmitry Khalanskiy
Get rid of Hamcrest, which is uncommon in this codebase, and replace as many `assert` statements from other testing frameworks as is reasonable with little automation by calls to `kotlin.test.*`.
2020-02-10Integration with binary-compatibility-validator plugin (#1790)Vsevolod Tolstopyatov
2020-01-28Request elements in batches in ReactiveFlow to avoid requesting elements one ↵Vsevolod Tolstopyatov
by one in a default configuration Also, partially masks #1766
2020-01-24Fix context support in Publisher.asFlow.flowOnRoman Elizarov
* When using asFlow().flowOn(...) context is now properly tracked and taken into account for both execution context of the reactive subscription and for injection into Reactor context. * Publisher.asFlow slow-path implementation is simplified. It does not sure specialized openSubscription anymore, but always uses the same flow request logic. Fixes #1765
2019-12-05Consistently handle undeliverable exceptions in RxJava and Reactor integrationsVsevolod Tolstopyatov
Use tryOnError in RxJava to make exception delivery check-and-act race free. Deliver undeliverable exceptions via RxJavaPlugins instead of handleCoroutineException. This is a deliberate choice for a multiple reasons: * When using Rx (whether with coroutines or not), undeliverable exceptions are inevitable and users should hook into RxJavaPlugins anyway. We don't want to force them using Rx-specific CoroutineExceptionHandler all over the place * Undeliverable exceptions provide additional helpful stacktrace and proper way to distinguish them from other unhandled exceptions * Be consistent with reactor where we don't have try*, thus cannot provide a completely consistent experience with CEH (at least, without wrapping all the subscribers)\ Do the similar in Reactor integration, but without try*, Reactor does not have notion of undeliverable exceoptions and handles them via Operators.* on its own. Also, get rid of ASCII tables that are not properly render in IDEA Fixes #252 Fixes #1614
2019-10-29Fix ReactorFlow integration bug exposed by TestBaseVsevolod Tolstopyatov
2019-10-29Add missing TestBase inheritance to fail on asynchronous errorsVsevolod Tolstopyatov
2019-09-25Remove outdated reactive guide and add section about Reactive Streams to flow.mdVsevolod Tolstopyatov
2019-09-25Deprecate obsolete reactive API, improve existing Reactive documentationVsevolod Tolstopyatov
* Remove obsolete rx-example module * Properly document interoperability with Reactor context * Update reactive readme
2019-09-25Promote rx2 extensions to stable, increase deprecation level for obsolete ↵Vsevolod Tolstopyatov
reactive primitives
2019-09-25Promote Publisher<T>.collect to stable APIVsevolod Tolstopyatov
2019-09-25Promote reactive adapters for Flow to stable APIVsevolod Tolstopyatov
2019-08-21Replace kotlinx.coroutines.reactive.FlowKt and ↵Vsevolod Tolstopyatov
kotlinx.coroutines.reactor.FlowKt with properly named files Otherwise, it leads to a weird classname clash and forces to write FQ imports
2019-08-09Coroutine context propagation for Reactor to coroutines API migration (#1377)SokolovaMaria
* Propagation of the coroutine context of await calls into Mono/Flux builder * Publisher.asFlow propagates coroutine context from `collect` call to the Publisher * Flow.asFlux transform * Optimized FlowSubscription * kotlinx.coroutines.reactor.flow package is replaced with kotlinx.coroutines.reactor Fixes #284
2019-07-19Report fatal errors to both onError (to comply the spec fully) and to ↵Vsevolod Tolstopyatov
coroutine context (to eagerly fail as fatal exceptions are not recoverable anyway), cleanup tests after scopeless reactive
2019-07-19Properly handle fatal exceptions in Rx coroutines, get rid of deadlock in ↵Vsevolod Tolstopyatov
RxObservable
2019-07-19Consistently handle fatal exceptions in PublisherCoroutineVsevolod Tolstopyatov
Fixes #1297
2019-07-17Context passing between coroutines and Reactor Mono/Flux (#1138)SokolovaMaria
Fixes #284
2019-07-16Reactive scopeless (#1341)Vsevolod Tolstopyatov
Make all reactive builders top-level functions instead of extensions on CoroutineScope and prohibit jobs in their context Downsides of having lifecycle-managed scoped builders: * The lifecycle of semantically cold entity is managed externally by the hot-one. * Independent failures in independent triggered computations affect each other * Two cancellation sources should be managed, coroutine-related Job parent and disposable/subscription
2019-07-03Update copyright year to 2019 in all the knit-generated filesRoman Elizarov