TL;DR;

  • ReactiveX is an API for asynchronous programming based on the observer pattern.
  • RxGo is the official Go implementation of ReactiveX (a cousin of RxJS, RxJava, etc.).
  • There are +50 new operators and multiple new features (hot vs cold observable, connectable observable, backpressure, etc.)
  • Yes, Go has already great concurrency primitives and yes, there is still no generics. Nonetheless, RxGo may still be worth a look.

Overview

In ReactiveX, the two main concepts are the Observer and the Observable.
An Observable is a bounded or unbounded stream of data. An Observer subscribes to an Observable. Then, it reacts to whatever item the Observable emits. There are operators to create or compose Observables.

Example
  • We define a transformation function (circle into a square) using Map operator.
  • We filter each yellow square using Filter operator.

Real-World Example with v2

First, we have to install RxGo v2:

go get -u github.com/reactivex/rxgo/v2
  • Enrich each customer with a tax number. Retrieving a tax number is performed in our example by a function calling a REST service.

What Else?

As part of the new features of RxGo v2, it is now possible to:

Statistics

On the v2 development:

  • 90 issues.
  • 17 participants.
  • 468 commits.
Follow me on Twitter @teivah

Software Engineer, Go, Rust, Java | 改善