<commit_before>---
layout: documentation
title: ReactiveX - Observable
id: observable
---

<h1>Observable</h1>
<p>
 In ReactiveX an <dfn>observer</dfn> <dfn>subscribes</dfn> to an <dfn>Observable</dfn>. Then that observer
 reacts to whatever item or sequence of items the Observable <dfn>emits</dfn>. This pattern facilitates
 concurrent operations because it does not need to block while waiting for the Observable to emit objects, but
 instead it creates a sentry in the form of an observer that stands ready to react appropriately at whatever
 future time the Observable does so.
</p><p>
 This page explains what the reactive pattern is and what Observables and observers are (and how observers
 subscribe to Observables). Other pages show how you use <a href="operators.html">the variety of Observable
 operators</a> to link Observables together and change their behaviors.
</p>
<figure>
 <figcaption><p>This documentation accompanies its explanations with &ldquo;marble diagrams.&rdquo; Here is how
 marble diagrams represent Observables and transformations of Observables:</p></figcaption>
 <img src="{{ site.url }}/assets/operators/legend.png" style="width:100%;" />
</figure>
<h4>See Also</h4>
<ul>
 <li><a href="single.html"><tt>Single</tt></a> &mdash; a specialized version of an Observable that emits only a single item</li>
 <li><a href="http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Introduction"><cite>Rx Workshop</cite>: Introduction</a></li>
 <li><a href="http://www.introtorx.com/Content/v1.0.10621.0/02_KeyTypes.html#IObservable"><cite>Introduction to Rx</cite>: IObservable</a></li>
 <li><a href="http://docs.couchbase.com/developer/java-2.0/observables.html"><cite>Mastering observables</cite></a> (from the Couchbase Server documentation)</li>
 <li><a href="https://medium.com/@andrestaltz/2-minute-introduction-to-rx-24c8ca793877"><cite>2 minute introduction to Rx</cite></a> by <NAME> (&ldquo;Think of an Observable as an asynchronous immutable array.&rdquo;)</li>
 <li><a href="https://egghead.io/lessons/javascript-introducing-the-observable">Introducing the Observable</a> by <NAME> (JavaScript Video Tutorial)</li>
 <li><a href="http://xgrommx.github.io/rx-book/content/observable/index.html">Observable object</a> (RxJS) by <NAME></li>
 <li><a href="https://afterecho.wordpress.com/2015/09/03/turning-a-callback-into-an-rx-observable/">Turning a callback into an Rx Observable</a> by @afterecho</li>
</ul>
<h1>Background</h1>
<p>
 In many software programming tasks, you more or less expect that the instructions you write will execute and
 complete incrementally, one-at-a-time, in order as you have written them. But in ReactiveX, many instructions
 may execute in parallel and their results are later captured, in arbitrary order, by “observers.” Rather than
 <em>calling</em> a method, you define a mechanism for retrieving and transforming the data, in the form of an
 “Observable,” and then <em>subscribe</em> an observer to it, at which point the previously-defined mechanism
 fires into action with the observer standing sentry to capture and respond to its emissions whenever they
 are ready.
</p><p>
 An advantage of this approach is that when you have a bunch of tasks that are not dependent on each other, you
 can start them all at the same time rather than waiting for each one to finish before starting the next one
 &mdash; that way, your entire bundle of tasks only takes as long to complete as the longest task in the bundle.
</p><p>
 There are many terms used to describe this model of asynchronous programming and design. This document will use
 the following terms: An <dfn>observer</dfn> <dfn>subscribes</dfn> to an <dfn>Observable</dfn>. An Observable
 <dfn>emits</dfn> <dfn>items</dfn> or sends <dfn>notifications</dfn> to its observers by calling the observers’
 methods.
</p><p>
 In other documents and other contexts, what we are calling an “observer” is sometimes called a “subscriber,”
 “watcher,” or “reactor.” This model in general is often referred to as the
 <a href="http://en.wikipedia.org/wiki/Reactor_pattern">“reactor pattern”</a>.<commit_msg>Fix dead link in Observable documentation page<commit_after>---
layout: documentation
title: ReactiveX - Observable
id: observable
---

<h1>Observable</h1>
<p>
 In ReactiveX an <dfn>observer</dfn> <dfn>subscribes</dfn> to an <dfn>Observable</dfn>. Then that observer
 reacts to whatever item or sequence of items the Observable <dfn>emits</dfn>. This pattern facilitates
 concurrent operations because it does not need to block while waiting for the Observable to emit objects, but
 instead it creates a sentry in the form of an observer that stands ready to react appropriately at whatever
 future time the Observable does so.
</p><p>
 This page explains what the reactive pattern is and what Observables and observers are (and how observers
 subscribe to Observables). Other pages show how you use <a href="operators.html">the variety of Observable
 operators</a> to link Observables together and change their behaviors.
</p>
<figure>
 <figcaption><p>This documentation accompanies its explanations with &ldquo;marble diagrams.&rdquo; Here is how
 marble diagrams represent Observables and transformations of Observables:</p></figcaption>
 <img src="{{ site.url }}/assets/operators/legend.png" style="width:100%;" />
</figure>
<h4>See Also</h4>
<ul>
 <li><a href="single.html"><tt>Single</tt></a> &mdash; a specialized version of an Observable that emits only a single item</li>
 <li><a href="http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Introduction"><cite>Rx Workshop</cite>: Introduction</a></li>
 <li><a href="http://www.introtorx.com/Content/v1.0.10621.0/02_KeyTypes.html#IObservable"><cite>Introduction to Rx</cite>: IObservable</a></li>
 <li><a href="http://docs.couchbase.com/developer/java-2.0/observables.html"><cite>Mastering observables</cite></a> (from the Couchbase Server documentation)</li>
 <li><a href="https://medium.com/@andrestaltz/2-minute-introduction-to-rx-24c8ca793877"><cite>2 minute introduction to Rx</cite></a> by <NAME> (&ldquo;Think of an Observable as an asynchronous immutable array.&rdquo;)</li>
 <li><a href="https://egghead.io/lessons/javascript-introducing-the-observable">Introducing the Observable</a> by <NAME> (JavaScript Video Tutorial)</li>
 <li><a href="http://xgrommx.github.io/rx-book/content/observable/index.html">Observable object</a> (RxJS) by <NAME></li>
 <li><a href="http://afterecho.uk/blog/turning-a-callback-into-an-rx-observable.html">Turning a callback into an Rx Observable</a> by @afterecho</li>
</ul>
<h1>Background</h1>
<p>
 In many software programming tasks, you more or less expect that the instructions you write will execute and
 complete incrementally, one-at-a-time, in order as you have written them. But in ReactiveX, many instructions
 may execute in parallel and their results are later captured, in arbitrary order, by “observers.” Rather than
 <em>calling</em> a method, you define a mechanism for retrieving and transforming the data, in the form of an
 “Observable,” and then <em>subscribe</em> an observer to it, at which point the previously-defined mechanism
 fires into action with the observer standing sentry to capture and respond to its emissions whenever they
 are ready.
</p><p>
 An advantage of this approach is that when you have a bunch of tasks that are not dependent on each other, you
 can start them all at the same time rather than waiting for each one to finish before starting the next one
 &mdash; that way, your entire bundle of tasks only takes as long to complete as the longest task in the bundle.
</p><p>
 There are many terms used to describe this model of asynchronous programming and design. This document will use
 the following terms: An <dfn>observer</dfn> <dfn>subscribes</dfn> to an <dfn>Observable</dfn>. An Observable
 <dfn>emits</dfn> <dfn>items</dfn> or sends <dfn>notifications</dfn> to its observers by calling the observers’
 methods.
</p><p>
 In other documents and other contexts, what we are calling an “observer” is sometimes called a “subscriber,”
 “watcher,” or “reactor.” This model in general is often referred to as the
 <a href="http://en.wikipedia.org/wiki/Reactor_pattern">“reactor pattern”</a>.
{'fraction_non_alphanumeric': 0.11517500302773405, 'fraction_numerical': 0.008962092769771104, 'mean_word_length': 5.144345238095238, 'pattern_counts': {'":': 0, '<': 201, '<?xml version=': 0, '>': 201, 'https://': 5, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2249178', 'n_tokens_mistral': 2460, 'n_tokens_neox': 2352, 'n_words': 943}