RxJava v1.1.7 发布,一个实现异步操作的库

jopen 8年前
   <p style="text-align: center;"><img alt="" src="https://simg.open-open.com/show/27e89a5a287f2aa133ed68e1e8b7e831.png" /></p>    <p>RxJava一个在 Java VM 上使用可观测的序列来组成异步的、基于事件的程序的库。说到根上,它就是一个实现异步操作的库,而别的定语都是基于这之上的。同样是做异步,为什么人们用它,而不用现成的 AsyncTask / Handler / XXX / ... ?,原因是RxJava简洁,异步操作很关键的一点是程序的简洁性,因为在调度过程比较复杂的情况下,异步代码经常会既难写也难被读懂。 Android 创造的 AsyncTask 和Handler ,其实都是为了让异步代码更加简洁。RxJava 的优势也是简洁,但它的简洁的与众不同之处在于,随着程序逻辑变得越来越复杂,它依然能够保持简洁。</p>    <p style="text-align: center;"><img alt="" src="https://simg.open-open.com/show/590895c0b975a817143b0f53b870e71b.jpg" /></p>    <p style="text-align: center;"><img alt="" src="https://simg.open-open.com/show/039f09fd6005089241137560455ed074.png" /></p>    <h2>更新日志</h2>    <p><strong>新的RxJavaHooks API</strong></p>    <p>PR <a href="/misc/goto?guid=4958992011394848987" title="1.x: new hook management proposal">#4007</a> introduced a new way of hooking into the lifecycle of the base reactive types (<code>Observable</code>,<code>Single</code>, <code>Completable</code>) and the <code>Scheduler</code>s. The original <code>RxJavaPlugins</code>' design was too much focused on class-initialization time hooking and didn't properly allow hooking up different behavior after that. There is a <code>reset()</code> available on it but sometimes that doesn't work as expected.</p>    <p>The new class <code>rx.plugins.RxJavaHooks</code> allows changing the hooks at runtime, allowing tests to temporarily hook onto an internal behavior and then un-hook once the test completed.</p>    <pre>  RxJavaHooks.setOnObservableCreate(s -> {     System.out.println("Observable created");     return s;  });    Observable.just(1).subscribe(System.out::println);    RxJavaHooks.reset();  // or  RxJavaHooks.setOnObservableCreate(null);</pre>    <p>It is now also possible to override what <code>Scheduler</code>s the <code>Schedulers.computation()</code>, <code>.io()</code> and<code>.newThread()</code> returns without the need to fiddle with <code>Schedulers</code>' own reset behavior:</p>    <pre>  RxJavaHooks.setOnComputationScheduler(current -> Schedulers.immediate());    Observable.just(1).subscribeOn(Schedulers.computation())  .subscribe(v -> System.out.println(Thread.currentThread()));</pre>    <p>By default, all <code>RxJavaHooks</code> delegate to the original <code>RxJavaPlugins</code> callbacks so if you have hooks the old way, they still work. <code>RxJavaHooks.reset()</code> resets to this delegation and <code>RxJavaHooks.clear()</code> clears all hooks (i.e., everything becomes a pass-through hook).</p>    <p><strong>API增强</strong></p>    <ul>     <li><a href="/misc/goto?guid=4958992011500032254">Pull 3966</a>: Add multi-other <code>withLatestFrom</code> operators.</li>     <li><a href="/misc/goto?guid=4958992011584961145">Pull 3720</a>: Add vararg of <code>Subscription</code>s to composite subscription.</li>     <li><a href="/misc/goto?guid=4958992011681175893">Pull 4034</a>: <code>distinctUntilChanged</code> with direct value comparator - alternative.</li>     <li><a href="/misc/goto?guid=4958992011783345065">Pull 4036</a>: Added zip function with Observable array.</li>     <li><a href="/misc/goto?guid=4958992011869615343">Pull 4020</a>: Add <code>AsyncCompletableSubscriber</code> that exposes <code>unsubscribe()</code>.</li>     <li><a href="/misc/goto?guid=4958992011953714739">Pull 4011</a>: Deprecate <code>TestObserver</code>, enhance <code>TestSubscriber</code> a bit.</li>     <li><a href="/misc/goto?guid=4958992011394848987">Pull 4007</a>: new hook management proposal</li>     <li><a href="/misc/goto?guid=4958992012056542514">Pull 4173</a>: allow customizing GenericScheduledExecutorService via RxJavaHooks</li>     <li><a href="/misc/goto?guid=4958992012153683399">Pull 3931</a>: add <code>groupBy</code> overload with <code>evictingMapFactory</code></li>     <li><a href="/misc/goto?guid=4958992012231637165">Pull 4140</a>: Change <code>Completable.subscribe(onError, onComplete)</code> to <code>(onComplete, onError)</code></li>     <li><a href="/misc/goto?guid=4958992012327061229">Pull 4154</a>: Ability to create custom schedulers with behavior based on composing operators via<code>Scheduler.when</code>.</li>     <li><a href="/misc/goto?guid=4958992012419763433">Pull 4179</a>: New <code>fromAsync</code> to bridge the callback world with the reactive.</li>    </ul>    <p><strong>API弃用</strong></p>    <ul>     <li><a href="/misc/goto?guid=4958992011953714739">Pull 4011</a>: Deprecate <code>TestObserver</code>, enhance <code>TestSubscriber</code> a bit.</li>     <li><a href="/misc/goto?guid=4958992011394848987">Pull 4007</a>: new hook management proposal (deprecates some <code>RxJavaPlugins</code> methods).</li>    </ul>    <p><strong>性能增强</strong></p>    <ul>     <li><a href="/misc/goto?guid=4958992012539062364">Pull 4097</a>: update <code>map()</code> and <code>filter()</code> to implement <code>OnSubscribe</code> directly.</li>     <li><a href="/misc/goto?guid=4958992012616428369">Pull 4176</a>: Optimize collect, reduce and takeLast(1)</li>    </ul>    <p><strong>Bug修复</strong></p>    <ul>     <li><a href="/misc/goto?guid=4958992012710647722">Pull 4027</a>: fix <code>Completable.onErrorComplete(Func1)</code> not relaying function crash.</li>     <li><a href="/misc/goto?guid=4958992012808563017">Pull 4051</a>: fix <code>ReplaySubject</code> anomaly around caughtUp by disabling that optimization.</li>    </ul>    <h2>下载</h2>    <ul>     <li><a href="/misc/goto?guid=4958992012900609005" rel="nofollow"><strong>Source code</strong> (zip)</a></li>     <li><a href="/misc/goto?guid=4958992012991986045" rel="nofollow"><strong>Source code</strong> (tar.gz)</a></li>    </ul>