2
头图

foreword

I recently jumped to a new company and found that the company's projects use a lot of RxJava3-related technologies, which makes me, a light user of the Rx series, at a loss.

As the saying goes, a thousand studies are better than a look, and a thousand studies are better than a practice. In order to quickly become familiar with and master RxJava3-related content, I referred to the official documents and combined the previous experience, and wrote a small learning project RxJava3Sample , which contains document introduction, examples, log display and source code.

In this way, I looked at the document and typed the code over and over again, and the speed of mastering was very fast. If you are interested in RxJava3, you might as well download the project and run it locally. The effect is absolutely beyond your imagination!

Well, without further ado, let me briefly introduce this project.

project address

https://github.com/xuexiangjys/RxJava3Sample

Demonstration effect

项目演示

Transmitter type

typedescribe
Observable<T>Capable of transmitting 0 or n data and terminating with a success or error event.
Flowable<T>Capable of transmitting 0 or n data and terminating with a success or error event. Backpressure is supported, which can control the speed at which the data source emits. Can be converted from Observable.
Single<T>Only emit a single data or error event. Only handle onNext and onError events, no onComplete.
CompletableIt never emits data, only handles onComplete and onError events. It can be regarded as the Runnable of Rx.
Maybe<T>Can emit 0 or 1 data, either succeed or fail. Similar to the combination of Single and Completable. If onNext and onError are handled, then onComplete is not handled.

Subject

Subject is both Observable and Observer (Subscriber)
typedescribe
PublishSubjectOnly receive all data after subscription
BehaviorSubjectReceive the last data before subscription and all data after subscription
AsyncSubjectOnly the last data is received
ReplaySubjectReceive all data before and after subscription
SerializedSubjectA thread-safe Subject, which can be converted from another Subject by calling toSerialized

Common operators

typeoperator
create typecreatejusttimerintervalfromerror
conversion typemapflatMapconcatMapswitchMapbuffer
filter typefilterofTypedebouncethrottleWithTimeoutdistinctdistinctUntilChangedfirstlasttakeskip
combination typemergezipcombineLatest
error handling typeretryonErrorResumeNext
Auxiliary Action TypedelaysubscribeOndototimeout
Conditions and Boolean TypesambcontainstakeUntilskipUntil
Arithmetic and Aggregate Typesreducemaxminsum

Scheduler

typedescribe
Schedulers.ioCache thread pool, infinite number of threads, used for I/O operations
Schedulers.computationFixed thread pool, the size is the number of CPU cores, for CPU-intensive computing (non-blocking)
Schedulers.singlesingle thread pool
Schedulers.newThreadStart a new thread for the specified task
Schedulers.trampolineWhen other queued tasks are completed, start execution in the current thread queue
Schedulers.fromUse the specified Executor as the scheduler
AndroidSchedulers.mainThreadAndroid's main thread, the UI thread

Plugins

Plugins, also known as Hooks, can modify the default behavior of Rxjava.

Using RxJavaPlugins, you can hook and customize the following three types of functions:

  • The lifecycle of emitters Observable, Single, Completable and Maybe (loaded and subscribed).
  • Rxjava's various thread schedulers Scheduler.
  • Rxjava global unhandled error.

Special thanks to

At last

If you think this project is helpful for you to learn RxJava3, you can click star to bookmark or share it, so that more people can understand and master RxJava3!

I am xuexiangjys, a technology up master who loves learning, programming, and is committed to Android architecture research and open source project experience sharing. For more information, welcome to WeChat search public : 161e6f22273bfa [My Android Open Source Journey]

xuexiangjys
357 声望4.1k 粉丝