RxJava v1.1.7 發布,一個實現異步操作的庫

jopen 8年前發布 | 13K 次閱讀 RxJava Java VM Android

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,SingleCompletable) and the Schedulers. 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 Schedulers the Schedulers.computation().io() and.newThread() returns without the need to fiddle with Schedulers' 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 original RxJavaPlugins callbacks so if you have hooks the old way, they still work. RxJavaHooks.reset() resets to this delegation and RxJavaHooks.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 Subscriptions to composite subscription.
  • Pull 4034distinctUntilChanged with direct value comparator - alternative.
  • Pull 4036: Added zip function with Observable array.
  • Pull 4020: Add AsyncCompletableSubscriber that exposes unsubscribe().
  • Pull 4011: Deprecate TestObserver, enhance TestSubscriber a bit.
  • Pull 4007: new hook management proposal
  • Pull 4173: allow customizing GenericScheduledExecutorService via RxJavaHooks
  • Pull 3931: add groupBy overload with evictingMapFactory
  • Pull 4140: Change Completable.subscribe(onError, onComplete) to (onComplete, onError)
  • Pull 4154: Ability to create custom schedulers with behavior based on composing operators viaScheduler.when.
  • Pull 4179: New fromAsync to bridge the callback world with the reactive.

API棄用

  • Pull 4011: Deprecate TestObserver, enhance TestSubscriber a bit.
  • Pull 4007: new hook management proposal (deprecates some RxJavaPlugins methods).

性能增強

  • Pull 4097: update map() and filter() to implement OnSubscribe 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.

下載

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!