Skip to content

Commit 187ba53

Browse files
committed
clarify observeOn/subscribeOn docs
fixes #135 see also ReactiveX/RxJava#3152
1 parent 9895223 commit 187ba53

File tree

4 files changed

+56
-12
lines changed

4 files changed

+56
-12
lines changed
411 KB
Loading

documentation/operators/observeon.html

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,28 @@ <h3>specify the Scheduler on which an observer will observe this Observable</h3>
3131
jumps ahead of (and swallows) items emitted by the source Observable, as in the diagram above.
3232
</p></figcaption>
3333
</figure>
34-
<p>
34+
<figure>
35+
<img src="images/schedulers.png" style="width:100%;" alt="ObserveOn and SubscribeOn" />
36+
<figcaption><p>
3537
The <a href="subscribeon.html"><span class="operator">SubscribeOn</span></a> operator is similar, but it
3638
instructs the Observable to <em>itself</em> operate on the specified Scheduler, as well as notifying its
3739
observers on that Scheduler.
38-
</p>
40+
</p><p>
41+
By default, an Observable and the chain of operators that you apply to it will do its work, and will notify
42+
its observers, on the same thread on which its <code>Subscribe</code> method is called. The
43+
<span class="operator">SubscribeOn</span> operator changes this behavior by specifying a different Scheduler
44+
on which the Observable should operate. The <span class="operator">ObserveOn</span> operator specifies a
45+
different Scheduler that the Observable will use to send notifications to its observers.
46+
</p><p>
47+
As shown in this illustration, the <span class="operator">SubscribeOn</span> operator designates which thread
48+
the Observable will begin operating on, no matter at what point in the chain of operators that operator is
49+
called. <span class="operator">ObserveOn</span>, on the other hand, affects the thread that the Observable
50+
will use <em>below</em> where that operator appears. For this reason, you may call
51+
<span class="operator">ObserveOn</span> multiple times at various points during the chain of Observable
52+
operators in order to change on which threads certain of those operators operate.
53+
</p></figcaption>
54+
</figure>
55+
3956

4057
<h4>See Also</h4>
4158
<ul>

documentation/operators/subscribeon.html

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ <h3>specify the Scheduler on which an Observable will operate</h3>
1818
<figcaption><p>
1919
Many implementations of ReactiveX use <a href="../scheduler.html">&ldquo;<code>Scheduler</code>s&rdquo;</a>
2020
to govern an Observable&#8217;s transitions between threads in a multi-threaded environment. You can instruct
21-
an Observable to operate on a particular Scheduler by means of the <span class="operator">SubscribeOn</span>
22-
operator.
21+
an Observable to do its work on a particular Scheduler by calling the Observable&#8217;s
22+
<span class="operator">SubscribeOn</span> operator.
2323
</p></figcaption>
2424
</figure>
2525
<p>
@@ -28,6 +28,23 @@ <h3>specify the Scheduler on which an Observable will operate</h3>
2828
</p><p>
2929
In some implementations there is also an <span class="operator">UnsubscribeOn</span> operator.
3030
</p>
31+
<figure>
32+
<img src="images/schedulers.png" style="width:100%;" alt="ObserveOn and SubscribeOn" />
33+
<figcaption><p>
34+
By default, an Observable and the chain of operators that you apply to it will do its work, and will notify
35+
its observers, on the same thread on which its <code>Subscribe</code> method is called. The
36+
<span class="operator">SubscribeOn</span> operator changes this behavior by specifying a different Scheduler
37+
on which the Observable should operate. The <span class="operator">ObserveOn</span> operator specifies a
38+
different Scheduler that the Observable will use to send notifications to its observers.
39+
</p><p>
40+
As shown in this illustration, the <span class="operator">SubscribeOn</span> operator designates which thread
41+
the Observable will begin operating on, no matter at what point in the chain of operators that operator is
42+
called. <span class="operator">ObserveOn</span>, on the other hand, affects the thread that the Observable
43+
will use <em>below</em> where that operator appears. For this reason, you may call
44+
<span class="operator">ObserveOn</span> multiple times at various points during the chain of Observable
45+
operators in order to change on which threads certain of those operators operate.
46+
</p></figcaption>
47+
</figure>
3148

3249
<h4>See Also</h4>
3350
<ul>

documentation/scheduler.markdown

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,25 @@ id: scheduler
1111
</p><p>
1212
Some ReactiveX Observable operators have variants that take a Scheduler as a parameter. These instruct the
1313
operator to do some or all of its work on a particular Scheduler.
14-
</p><p>
15-
You can make an Observable act on a particular Scheduler by means of the
16-
<a href="operators/observeon.html"><span class="operator">ObserveOn</span></a> or
17-
<a href="operators/subscribeon.html"><span class="operator">SubscribeOn</span></a> operators.
18-
<span class="operator">ObserveOn</span> instructs an Observable to call its observer&#8217;s
19-
<code>onNext</code>, <code>onError</code>, and <code>onCompleted</code> methods on a particular Scheduler;
20-
<span class="operator">SubscribeOn</span> takes this a step further and instructs the Observable to do all of
21-
its processing (including the sending of items and notifications to observers) on a particular Scheduler.
2214
</p>
15+
<figure>
16+
<figcaption><p>
17+
By default, an Observable and the chain of operators that you apply to it will do its work, and will notify
18+
its observers, on the same thread on which its <code>Subscribe</code> method is called. The
19+
<span class="operator">SubscribeOn</span> operator changes this behavior by specifying a different Scheduler
20+
on which the Observable should operate. The <span class="operator">ObserveOn</span> operator specifies a
21+
different Scheduler that the Observable will use to send notifications to its observers.
22+
</p><p>
23+
As shown in this illustration, the <span class="operator">SubscribeOn</span> operator designates which thread
24+
the Observable will begin operating on, no matter at what point in the chain of operators that operator is
25+
called. <span class="operator">ObserveOn</span>, on the other hand, affects the thread that the Observable
26+
will use <em>below</em> where that operator appears. For this reason, you may call
27+
<span class="operator">ObserveOn</span> multiple times at various points during the chain of Observable
28+
operators in order to change on which threads certain of those operators operate.
29+
</p></figcaption>
30+
<img src="operators/images/schedulers.png" style="width:100%;" alt="ObserveOn and SubscribeOn" />
31+
</figure>
32+
2333
<h4>See Also</h4>
2434
<ul>
2535
<li><a href="http://www.introtorx.com/Content/v1.0.10621.0/15_SchedulingAndThreading.html"><cite>Introduction to Rx</cite>: Scheduling and Threading</a></li>

0 commit comments

Comments
 (0)