Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/JakeWharton/RxReplayingShare
An RxJava transformer which combines replay(1), publish(), and refCount() operators.
https://github.com/JakeWharton/RxReplayingShare
Last synced: 25 days ago
JSON representation
An RxJava transformer which combines replay(1), publish(), and refCount() operators.
- Host: GitHub
- URL: https://github.com/JakeWharton/RxReplayingShare
- Owner: JakeWharton
- License: apache-2.0
- Created: 2016-03-01T06:41:06.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2022-09-05T07:00:43.000Z (over 2 years ago)
- Last Synced: 2024-10-14T12:24:46.598Z (about 2 months ago)
- Language: Java
- Homepage:
- Size: 563 KB
- Stars: 626
- Watchers: 26
- Forks: 28
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-rxjava - RxReplayingShare - An RxJava transformer which combines replay(1), publish(), and refCount() operators. (Utilities)
README
RxJava Replaying Share
======================`ReplayingShare` is an RxJava 3 transformer which combines `replay(1)`, `publish()`, and
`refCount()` operators.Unlike traditional combinations of these operators, `ReplayingShare` caches the last emitted
value from the upstream observable or flowable *only* when one or more downstream subscribers are
connected. This allows expensive upstream sources to be shut down when no one is listening while
also replaying the last value seen by *any* subscriber to new ones.| | replayingShare() | replay(1).refCount() | publish().refCount() | replay(1).autoConnect(1) |
|----------------------------------------------------------------------------------|------------------|----------------------|----------------------| -------------------------|
| Disconnects from upstream when there are no subscribers | ✅ | ✅ | ✅ | ❌ |
| Replays the latest value to new subscribers when other subscribers are active | ✅ | ✅ | ❌ | ✅ |
| Replays the latest value to new subscribers when no other subscribers are active | ✅ | ❌ | ❌ | ✅ |![marble diagram](marbles.png)
Usage
-----Apply with `compose` to an upstream `Observable` or `Flowable` and cache the resulting instance for
all new subscribers.```java
@Singleton class Chart {
private final Observable chart;@Inject Chart(Observable> data) {
chart = data.debounce(1, SECONDS)
.map(list -> bigExpensiveRenderChartToBitmapFunction(list))
.compose(ReplayingShare.instance());
}Observable data() {
return chart;
}
}
```Kotlin users can use the operator via an extension function.
```kotlin
@Singleton class Chart
@Inject constructor(data: Observable>) {
val chart: Observable = data.debounce(1, SECONDS)
.map(list -> bigExpensiveRenderChartToBitmapFunction(list))
.replayingShare()
}
```Note: This operator is designed for composition with infinite or extremely long-lived streams. Any
terminal event will clear the cached value.Download
--------Gradle:
```groovy
implementation 'com.jakewharton.rx3:replaying-share:3.0.0'
// Optional:
implementation 'com.jakewharton.rx3:replaying-share-kotlin:3.0.0'
```
Maven:
```xmlcom.jakewharton.rx3
replaying-share
3.0.0com.jakewharton.rx3
replaying-share-kotlin
3.0.0```
Snapshots of the development version are available in [Sonatype's `snapshots` repository][snap].
### RxJava 2.x
Gradle:
```groovy
implementation 'com.jakewharton.rx2:replaying-share:2.2.0'
// Optional:
implementation 'com.jakewharton.rx2:replaying-share-kotlin:2.2.0'
```
Maven:
```xmlcom.jakewharton.rx2
replaying-share
2.2.0com.jakewharton.rx2
replaying-share-kotlin
2.2.0```
### RxJava 1.x
Gradle:
```groovy
implementation 'com.jakewharton.rx:replaying-share:1.0.1'
// Optional:
implementation 'com.jakewharton.rx:replaying-share-kotlin:1.0.1'
```
Maven:
```xmlcom.jakewharton.rx
replaying-share
1.0.1com.jakewharton.rx
replaying-share-kotlin
1.0.1```
License
-------Copyright 2016 Jake Wharton
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.[snap]: https://oss.sonatype.org/content/repositories/snapshots/