-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements a completable convert into a Mono with no values, using in…
…ternal converts of Completable, such #toObservable(), so we can reuse the converts 'to' and 'from' publisher from DependencyUtils.java Enabling RxCompletable only when it is present on classpath
- Loading branch information
1 parent
da92949
commit befa46d
Showing
4 changed files
with
288 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/reactor/core/converter/RxJava1CompletableConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package reactor.core.converter; | ||
|
||
import org.reactivestreams.Publisher; | ||
import reactor.core.publisher.Mono; | ||
import rx.Completable; | ||
import rx.Single; | ||
|
||
/** | ||
* Convert a {@link Publisher Publisher} into a Completable | ||
* | ||
* @author Joao Pedro Evangelista | ||
* @since 2.5 | ||
*/ | ||
public class RxJava1CompletableConverter extends PublisherConverter<Completable> { | ||
|
||
static final RxJava1CompletableConverter INSTANCE = new RxJava1CompletableConverter(); | ||
|
||
@SuppressWarnings("TypeMayBeWeakened") | ||
static Completable from(Mono<Void> noValue) { | ||
return INSTANCE.fromPublisher(noValue); | ||
} | ||
|
||
static Mono<Void> from(Completable completable) { | ||
return INSTANCE.toPublisher(completable); | ||
} | ||
|
||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
protected Mono<Void> toPublisher(Object o) { | ||
if (o instanceof Completable) { | ||
Publisher<?> publisher = DependencyUtils.<Void>convertToPublisher(((Completable) o).<Void>toObservable()); | ||
return Mono.from((Publisher<? extends Void>) publisher); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
protected Completable fromPublisher(Publisher<?> source) { | ||
return Completable.fromSingle(DependencyUtils.convertFromPublisher(source, Single.class)); | ||
} | ||
|
||
@Override | ||
public Class<Completable> get() { | ||
return Completable.class; | ||
} | ||
} |
Oops, something went wrong.