Originally posted this article on the Wedding Party tech blog
Ok, so in my previous post I innocuously introduced the .share()
operator.
Observable<Object> tapEventEmitter = _rxBus.toObserverable().share();
What is this share operator?
The .share()
operator is basically just a wrapper to the chained call .publish().refcount()
.
You’ll find the chained combo .publish().refcount()
used in quite a few Rx examples on the web. It allows you to “share” the emission of the stream. Considering how powerpacked and frequently used this combo is, RxJava basically introduced the friendlier more useful operator share()
. This mechanism is sometimes referred to as “multicasting”.