ReactiveX

ReactiveX
Other namesReactive Extensions
Original author(s)Microsoft
Developer(s)ReactiveX contributors
Initial releaseJune 21, 2011; 13 years ago (2011-06-21)
Repositorygithub.com/ReactiveX
Written inJava, Scala, C#, C++, Clojure, JavaScript, Python, Groovy, JRuby, and others
PlatformCross-platform
TypeAPI
LicenseApache License 2.0,
MIT License
Websitereactivex.io

ReactiveX (Rx, also known as Reactive Extensions) is a software library originally created by Microsoft that allows imperative programming languages to operate on sequences of data regardless of whether the data is synchronous or asynchronous. It provides a set of sequence operators that operate on each item in the sequence. It is an implementation of reactive programming and provides a blueprint for the tools to be implemented in multiple programming languages.

Overview

ReactiveX is an API for asynchronous programming with observable streams.[1]

Asynchronous programming allows programmers to call functions and then have the functions "callback" when they are done, usually by giving the function the address of another function to execute when it is done. Programs designed in this way often avoid the overhead of having many threads constantly starting and stopping.

Observable streams (i.e. streams that can be observed) in the context of Reactive Extensions are like event emitters that emit three events: next, error, and complete. An observable emits next events until it either emits an error event or a complete event. However, at that point it will not emit any more events, unless it is subscribed to again.

Motivation

For sequences of data, it combines the advantages of iterators with the flexibility of event-based asynchronous programming. It also works as a simple promise, eliminating the pyramid of doom that results from multiple layers of callbacks.

Observables and observers

ReactiveX is a combination of ideas from the observer and the iterator patterns and from functional programming.[2]

An observer subscribes to an observable sequence. The sequence then sends the items to the observer one at a time, usually by calling the provided callback function. The observer handles each one before processing the next one. If many events come in asynchronously, they must be stored in a queue or dropped. In ReactiveX, an observer will never be called with an item out of order or (in a multi-threaded context) called before the callback has returned for the previous item. Asynchronous calls remain asynchronous and may be handled by returning an observable.

It is similar to the iterators pattern in that if a fatal error occurs, it notifies the observer separately (by calling a second function). When all the items have been sent, it completes (and notifies the observer by calling a third function). The Reactive Extensions API also borrows many of its operators from iterator operators in other programming languages.

Reactive Extensions is different from functional reactive programming as the Introduction to Reactive Extensions explains:

It is sometimes called "functional reactive programming" but this is a misnomer. ReactiveX may be functional, and it may be reactive, but "functional reactive programming" is a different animal. One main point of difference is that functional reactive programming operates on values that change continuously over time, while ReactiveX operates on discrete values that are emitted over time. (See Conal Elliott's work for more-precise information on functional reactive programming.)[2]

Reactive operators

An operator is a function that takes one observable (the source) as its first argument and returns another observable (the destination, or outer observable). Then for every item that the source observable emits, it will apply a function to that item, and then emit it on the destination Observable. It can even emit another Observable on the destination observable. This is called an inner observable.

An operator that emits inner observables can be followed by another operator that in some way combines the items emitted by all the inner observables and emits the item on its outer observable. Examples include:

  • switchAll – subscribes to each new inner observable as soon as it is emitted and unsubscribes from the previous one.
  • mergeAll – subscribes to all inner observables as they are emitted and outputs their values in whatever order it receives them.
  • concatAll – subscribes to each inner observable in order and waits for it to complete before subscribing to the next observable.

Operators can be chained together to create complex data flows that filter events based on certain criteria. Multiple operators can be applied to the same observable.

Some of the operators that can be used in Reactive Extensions may be familiar to programmers who use functional programming language, such as map, reduce, group, and zip.[3] There are many other operators available in Reactive Extensions, though the operators available in a particular implementation for a programming language may vary.

Reactive operator examples

Here is an example of using the map and reduce operators. We create an observable from a list of numbers. The map operator will then multiply each number by two and return an observable. The reduce operator will then sum up all the numbers provided to it (the value of 0 is the starting point). Calling subscribe will register an observer that will observe the values from the observable produced by the chain of operators. With the subscribe method, we are able to pass in an error-handling function, called whenever an error is emitted in the observable, and a completion function when the observable has finished emitting items.

import { of, Observable, map, reduce } from 'rxjs';

const source: Observable<number> = of(1, 2, 3, 4, 5);
source
  .pipe(
    map((value) => value * 2),
    reduce((sum, value) => sum + value, 0)
  )
  .subscribe({
    next: (value) => {
      console.log(value);
    },
    error: (error) => {
      console.error(error);
    },
    complete: () => {
      console.log('done');
    },
  });

The above example uses the RxJS implementation of Reactive Extensions for the JavaScript programming language.

History

Reactive Extensions (Rx) was created by the Cloud Programmability Team at Microsoft around 2011, as a byproduct of a larger effort called Volta. It was originally intended to provide an abstraction for events across different tiers in an application to support tier splitting in Volta. The project's logo represents an electric eel, which is a reference to Volta. The extensions suffix in the name is a reference to the Parallel Extensions technology which was invented around the same time; the two are considered complementary.

The initial implementation of Rx was for .NET Framework and was released on June 21, 2011. Later, the team started the implementation of Rx for other platforms, including JavaScript and C++. The technology was released as open source in late 2012, initially on CodePlex. Later, the code moved to GitHub.

See also

References

  1. ^ "ReactiveX". reactivex.io. Retrieved 2020-02-20.
  2. ^ a b "ReactiveX - Introduction". ReactiveX.io. Retrieved 23 September 2018.
  3. ^ "ReactiveX - Operators". ReactiveX.io. Retrieved 23 September 2018.

Read other articles:

Katedral SosnowiecKatedral Basilika Santa Perawan Maria Diangkat ke Surga, SosnowiecPolandia: Bazylika katedralna Wniebowzięcia Najświętszej Maryi Pannycode: pl is deprecated Katedral SosnowiecLokasiSosnowiecNegara PolandiaDenominasiGereja Katolik RomaSejarahDidirikan1899ArsitekturStatusKatedralStatus fungsionalAktifAdministrasiKeuskupanKeuskupan Sosnowiec Basilika Katedral Santa Perawan Maria Diangkat ke Surga [1] (Polandia: Bazylika katedralna Wniebowzięcia Najświętszej M...

 

Chapter of the Judeo-Christian Bible Zechariah 14← chapter 13Malachi 1 →Book of Zechariah (13:9-14:21) in Latin in Codex Gigas, made around 13th century.BookBook of ZechariahCategoryNevi'imChristian Bible partOld TestamentOrder in the Christian part38 Zechariah 14 is the fourteenth (and the final) chapter in the Book of Zechariah in the Hebrew Bible and the Old Testament of the Christian Bible.[1][2][3] This book contains the prophecies attributed to the ...

 

Zoologi Cabang Antropologi · Antrozoologi · ApiologiAraknologi · Artropodologi · CetologiConchologi · Entomologi · EtologiHelminthologi · Herpetologi · IktiologiMalacologi · Mammalogi · MyrmecologiNematologi · Neuroetologi · OrnitologiPaleozoologi · Planktologi · PrimatologiZoosemiotik Zoologis terkemuka Karl Ernst von Baer · Geor...

Cet article est une ébauche concernant le Mexique et une unité ou formation militaire. Vous pouvez partager vos connaissances en l’améliorant (comment ?) selon les recommandations des projets correspondants. Consultez la liste des tâches à accomplir en page de discussion. Forces militaires navales du Mexique(es) Armada de México Logo de la marine mexicaine. Création 1821 Pays Mexique Type Marine de guerre Effectif 75 181 (2 022) [1] Fait partie de Forces armées mexic...

 

Questa voce o sezione sull'argomento isole d'Italia non cita le fonti necessarie o quelle presenti sono insufficienti. Puoi migliorare questa voce aggiungendo citazioni da fonti attendibili secondo le linee guida sull'uso delle fonti. SpargiGeografia fisicaLocalizzazioneMar Tirreno Coordinate41°14′36″N 9°20′51″E / 41.243333°N 9.3475°E41.243333; 9.3475Coordinate: 41°14′36″N 9°20′51″E / 41.243333°N 9.3475°E41.243333; 9.3475 Arcipelag...

 

Hiding messages in other messages For the process of writing in shorthand, see Stenography. For the prefix Stego- as used in taxonomy, see List of commonly used taxonomic affixes. The same image viewed by white, blue, green, and red lights reveals different hidden numbers. Steganography (/ˌstɛɡəˈnɒɡrəfi/ ⓘ STEG-ə-NOG-rə-fee) is the practice of representing information within another message or physical object, in such a manner that the presence of the information is not evide...

Синелобый амазон Научная классификация Домен:ЭукариотыЦарство:ЖивотныеПодцарство:ЭуметазоиБез ранга:Двусторонне-симметричныеБез ранга:ВторичноротыеТип:ХордовыеПодтип:ПозвоночныеИнфратип:ЧелюстноротыеНадкласс:ЧетвероногиеКлада:АмниотыКлада:ЗавропсидыКласс:Пт�...

 

Ekstremofil (dari bahasa Latin extremus yang berarti ekstrem dan bahasa Yunani philiā (φιλία) yang berarti cinta) adalah mikrob yang menyukai lingkungan habitat ekstrem untuk kelangsungan hidupnya. Mikrob-mikrob ini justru tidak dapat berkembang di lingkungan di mana sebagian besar makhluk hidup lain dapat hidup dengan nyaman di dalamnya.[1] Sebagai contoh, hipertermofil mempunyai enzim yang sangat stabil dan hanya dapat bereaksi pada suhu tinggi. Enzim seperti ini sangat ideal ...

 

American actress (born 1964) Lori LoughlinLoughlin in 2016BornLori Anne Loughlin (1964-07-28) July 28, 1964 (age 59)New York City, U.S.EducationHauppauge High SchoolOccupation Actress Years active1979–presentKnown forRebecca Donaldson Katsopolis in Full HouseJody Travis in The Edge of NightSpouses Michael R. Burns ​ ​(m. 1989; div. 1996)​ Mossimo Giannulli ​(m. 1997)​ Children2, including Olivia Jade...

弗雷德里克·齊盧巴Frederick Chiluba第2任赞比亚总统任期1991年11月2日—2002年1月2日副职利维·姆瓦纳瓦萨前任肯尼思·卡翁达继任利维·姆瓦纳瓦萨 个人资料出生(1943-04-30)1943年4月30日北罗得西亚基特韦逝世2011年6月18日(2011歲—06—18)(68歲) 尚比亞卢萨卡(Lusaka)墓地 尚比亞卢萨卡使館公園總統陵園(英语:Embassy Park Presidential Burial)国籍赞比亚政党多黨民主運動(MMD)...

 

В Википедии есть статьи о других людях с такой фамилией, см. Скотт; Скотт, Джон. Джон Уолтер Скоттангл. John Walter Scott Дата рождения 2 ноября 1845(1845-11-02)[1] Место рождения Лондон, Великобритания[2] Дата смерти 4 января 1919(1919-01-04)[1] (73 года) Место смерти Нью-Йорк, Нью-�...

 

Film festival screening works by women, takes place in Newfoundland and Labrador, Canada St. John's International Women's Film FestivalLocationSt. John's, Newfoundland and LabradorEstablished1989Most recentOctober 17-21, 2023AwardsMost Promising FilmmakerWebsitewww.womensfilmfestival.com St. John's International Women's Film Festival (SJIWWF) is an annual film festival based in St. John's, Newfoundland and Labrador, highlighting films by women. It is one of the longest-running festiva...

يفتقر محتوى هذه المقالة إلى الاستشهاد بمصادر. فضلاً، ساهم في تطوير هذه المقالة من خلال إضافة مصادر موثوق بها. أي معلومات غير موثقة يمكن التشكيك بها وإزالتها. (نوفمبر 2019) دوري كرة القدم الإسكتلندي الدرجة الثانية 1954–55 تفاصيل الموسم دوري كرة القدم الاسكتلندي الدرجة الثانية...

 

Iguanodon Periode Kapur Awal 126–122 jtyl PreЄ Є O S D C P T J K Pg N ↓ I. bernissartensis dipajang pada postur kuadrupedal, Royal Belgian Institute of Natural Sciences, Brussels.TaksonomiKerajaanAnimaliaFilumChordataKelasReptiliaOrdoOrnithischiaFamiliIguanodontidaeGenusIguanodon Mantell, 1825 Tata namaSinonim takson Delapparentia turolensis Ruiz-Omeñaca, 2011[1] Other species †I. anglicus Holl, 1829 (nomen dubium) †I. galvensis Verdú et al., 2015[2] lbs ...

 

بوينغ سي-32معلومات عامةالنوع طائرة ذات بدن ضيقبلد الأصل  الولايات المتحدةالتسمية العسكرية C-32 المهام جسر جوي التطوير والتصنيعالصانع بوينغطورت من بوينغ 757سيرة الطائرةدخول الخدمة 1998أحداث هامة contract awarding (en) [1] (1996)توصيل[2][1] (1998 – 1998)توصيل[2] (2010 – 2019) الخدمةال�...

Untuk kegunaan lain, lihat Pretty Little Liars (disambiguasi). Pretty Little LiarsGenre Misteri Roman Cerita seru Fiksi kejahatan Drama Berdasarkan Sara Shepard (seri buku) I. Marlene King (seri televisi) PengembangI. Marlene KingSkenario Damas Cendekia Grace Whent Wicaksono Wisnu Legowo Azhar Amirulhisyam SutradaraEmil HeradiPengarah kreatifAngela HalimPemeran Yuki Kato Anya Geraldine Eyka Farhana Valerie Thomas Shindy Huang Wulan Guritno Tarra Budiman Naufal Samudra Jennifer Coppen Cindy Ni...

 

هذه المقالة يتيمة إذ تصل إليها مقالات أخرى قليلة جدًا. فضلًا، ساعد بإضافة وصلة إليها في مقالات متعلقة بها. (أبريل 2019) هوراسيو مارتينيز معلومات شخصية الميلاد سنة 1915   مقاطعة سانتياغو  تاريخ الوفاة سنة 1992 (76–77 سنة)  مواطنة الولايات المتحدة  الحياة العملية المهنة ل�...

 

Questa voce sull'argomento ciclisti spagnoli è solo un abbozzo. Contribuisci a migliorarla secondo le convenzioni di Wikipedia. Iñaki Gastón CrespoNazionalità Spagna Ciclismo SpecialitàStrada Termine carriera1994 CarrieraSquadre di club 1984-1985 Reynolds1986-1987 KAS1988-1989 Kelme1990-1993 CLAS1994 Mapei Nazionale 1985-1990 Spagna   Modifica dati su Wikidata · Manuale Iñaki Gastón Crespo (Bilbao, 25 maggio 1963) è un ex ciclista su stra...

Professional wrestling multi-competitor match type A 25-Diva battle royal held at WrestleMania XXV. Male wrestler Santino Marella won the match dressed as his fictional twin sister, Santina. In professional wrestling, a battle royal (sometimes battle royale; plural battles royal or battle royals[1]) is a multi-competitor match type in which wrestlers are eliminated until one is left and declared the winner. Typical battles royal begin with a number of participants in the ring, who are...

 

Sumatera UtaraBekas Daerah pemilihan Daerah Pemilihan /untuk Dewan Perwakilan RakyatRepublik IndonesiaWilayahSeluruh wilayah Sumatera UtaraDaerah pemilihan bekasDibentuk1955–1959 (periode pertama); 1971Dibubarkan2004Anggota15 (1956—59)17 (1971—77)18 (1977—82)19 (1982—92)23 (1992—1999)24 (1999—2004)Digantikan olehDI Aceh; Sumatera Utara I; Sumatera Utara II; Sumatera Utara IIIDibentuk dariTidak ada, daerah pemilihan baru Sumatera Utara adalah sebuah bekas daerah pemilihan dalam p...