rx overview
Combine reactive sources, generic methods, Go iterators, and cancellable subscriptions.
Use rx to process data item by item, handle asynchronous events, or merge multiple inputs. An Observable can emit multiple values followed by at most one completion or error event. Operators compose in the order you write them, and the generic Observable.Map method can change the output type.
Installation
You need Go 1.27 or later. Run the installation command in your Go module.
go get github.com/luminyra/rxWays to consume a stream
- Use
Observable.Collectto collect values into a slice. - Use
Observable.Allwith a Go range loop to receive values and errors. - Use
Observable.Subscribewith anObserverto register callbacks for values, errors, and completion. A subscription takes a standard-librarycontext.Contextfor cancellation and deadlines.
Go standard library integration
Use ordinary iterators for synchronous data and Go channels for asynchronous data. rx lets you compose those sources under one set of event, cancellation, and termination rules. Operators use Go 1.27 methods, and All exposes the results to a for range loop.
Performance
Collecting 1,000 values after Filter and Map takes about 12 µs, or 12 ns per value. The operators are fused into the source without additional locking. Delivering each value to a loop with All adds a handoff between goroutines and takes about 100 ns per value. Use Collect or Subscribe for high throughput.
The quickstart filters, maps, and takes values from a stream of numbers.