reactivex / rxjavajoins Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
Has this project been deprecated?
Are there any plan to continue support RxJava 2.x?
The following code throws a:
java.lang.NoSuchMethodError: rx.functions.Actions.onErrorFrom(Lrx/Observer;)Lrx/functions/Action1;
What went wrong?
import rx.lang.scala.ImplicitFunctionConversions._
import rx.lang.scala.JavaConversions._
def sendIndexFromThread(s: Subject[Int], repeats: Int) = new Thread(new Runnable {
def run() {
var i = 0
while (i < repeats) {
s.onNext(i)
i = i + 1
}
s.onCompleted()
}
})
val internalSize = 1024
val s1 = Subject[Int]
val s2 = Subject[Int]
val o1 = s1.onBackpressureBuffer.observeOn(NewThreadScheduler())
val o2 = s2.onBackpressureBuffer.observeOn(NewThreadScheduler())
val gotAll = new CountDownLatch(internalSize * 2)
val latch = new CountDownLatch(1)
val counter = new AtomicInteger(0)
val p1 = JoinObservable.from(o1).then((x: Int) => {
counter.incrementAndGet()
if (counter.get == (internalSize * 2)) { latch.countDown }
})
val p2 = JoinObservable.from(o2).then((x: Int) => {
counter.incrementAndGet()
if (counter.get == (internalSize * 2)) { latch.countDown }
})
val obs = JoinObservable.when(p1, p2).toObservable
obs.subscribe((_: Unit) => gotAll.countDown, (_: Throwable) => (), () => ())
val thread1 = sendIndexFromThread(s1, internalSize)
val thread2 = sendIndexFromThread(s2, internalSize)
thread1.start()
thread2.start()
latch.await
gotAll.await
thread1.join()
thread2.join()
I´m using plan to do it
Observable<Track> trackObservable = Track.get(pickLocation, dropLocation);
Observable<UploadedFile> uploadedFileObservable = uploadImage(bitmapPath);
Observable<OrderData> orderDataObservable = Observable.just(order);
Observable<Address> pickObservable = Address.get(order.getPickAddress());
Observable<Address> dropObservable = Address.get(order.getDropAddress());
Plan0<Observable<Order>> plan = JoinObservable.from(pickObservable)
.and(dropObservable)
.and(trackObservable)
.and(uploadedFileObservable)
.and(orderDataObservable)
.then(Order::create);
return JoinObservable.when(plan).toObservable().flatMap(orderObservable -> orderObservable);
...
private static Observable<Order> create(Address pickAddress, Address dropAddress, Track track,
UploadedFile image, OrderData orderData) {
...
return SERVICE.createOrder(newOrder)
.map(order -> {
save(order);
return order;
});
}
I do toObservable().flatMap(orderObservable -> orderObservable);
becuase createOrder generates an observable then .then(Order::create);
creates an Observer<Observer<Order>>
.
But don´t work.
I can´t find a way to chain multiple observers results into another observer :(
The 'join' and groupJoin operators need a backpressure story
Originally from ReactiveX/RxJava#1478
See ReactiveX/RxJava#1698 for where these operators are moved over.
The "observables" package is contained both by rx itself and rx-joins. This causes a split package which is specially problematic when using OSGi.
The best solution to avoid this would be to rename the observables package to something else.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.