RxJava v1.1.7 發布,一個實現異步操作的庫
RxJava一個在 Java VM 上使用可觀測的序列來組成異步的、基于事件的程序的庫。說到根上,它就是一個實現異步操作的庫,而別的定語都是基于這之上的。同樣是做異步,為什么人們用它,而不用現成的 AsyncTask / Handler / XXX / ... ?,原因是RxJava簡潔,異步操作很關鍵的一點是程序的簡潔性,因為在調度過程比較復雜的情況下,異步代碼經常會既難寫也難被讀懂。 Android 創造的 AsyncTask 和Handler ,其實都是為了讓異步代碼更加簡潔。RxJava 的優勢也是簡潔,但它的簡潔的與眾不同之處在于,隨著程序邏輯變得越來越復雜,它依然能夠保持簡潔。
更新日志
新的RxJavaHooks API
PR #4007 introduced a new way of hooking into the lifecycle of the base reactive types (Observable
,Single
, Completable
) and the Scheduler
s. The original RxJavaPlugins
' design was too much focused on class-initialization time hooking and didn't properly allow hooking up different behavior after that. There is a reset()
available on it but sometimes that doesn't work as expected.
The new class rx.plugins.RxJavaHooks
allows changing the hooks at runtime, allowing tests to temporarily hook onto an internal behavior and then un-hook once the test completed.
RxJavaHooks.setOnObservableCreate(s -> { System.out.println("Observable created"); return s; });Observable.just(1).subscribe(System.out::println);
RxJavaHooks.reset(); // or RxJavaHooks.setOnObservableCreate(null);</pre>
It is now also possible to override what
Scheduler
s theSchedulers.computation()
,.io()
and.newThread()
returns without the need to fiddle withSchedulers
' own reset behavior:RxJavaHooks.setOnComputationScheduler(current -> Schedulers.immediate());Observable.just(1).subscribeOn(Schedulers.computation()) .subscribe(v -> System.out.println(Thread.currentThread()));</pre>
By default, all
RxJavaHooks
delegate to the originalRxJavaPlugins
callbacks so if you have hooks the old way, they still work.RxJavaHooks.reset()
resets to this delegation andRxJavaHooks.clear()
clears all hooks (i.e., everything becomes a pass-through hook).API增強
- Pull 3966: Add multi-other
withLatestFrom
operators. - Pull 3720: Add vararg of
Subscription
s to composite subscription. - Pull 4034:
distinctUntilChanged
with direct value comparator - alternative. - Pull 4036: Added zip function with Observable array.
- Pull 4020: Add
AsyncCompletableSubscriber
that exposesunsubscribe()
. - Pull 4011: Deprecate
TestObserver
, enhanceTestSubscriber
a bit. - Pull 4007: new hook management proposal
- Pull 4173: allow customizing GenericScheduledExecutorService via RxJavaHooks
- Pull 3931: add
groupBy
overload withevictingMapFactory
- Pull 4140: Change
Completable.subscribe(onError, onComplete)
to(onComplete, onError)
- Pull 4154: Ability to create custom schedulers with behavior based on composing operators via
Scheduler.when
. - Pull 4179: New
fromAsync
to bridge the callback world with the reactive.
API棄用
- Pull 4011: Deprecate
TestObserver
, enhanceTestSubscriber
a bit. - Pull 4007: new hook management proposal (deprecates some
RxJavaPlugins
methods).
性能增強
- Pull 4097: update
map()
andfilter()
to implementOnSubscribe
directly. - Pull 4176: Optimize collect, reduce and takeLast(1)
Bug修復
- Pull 4027: fix
Completable.onErrorComplete(Func1)
not relaying function crash. - Pull 4051: fix
ReplaySubject
anomaly around caughtUp by disabling that optimization.