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
type | describe |
---|---|
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. |
Completable | It 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)
type | describe |
---|---|
PublishSubject | Only receive all data after subscription |
BehaviorSubject | Receive the last data before subscription and all data after subscription |
AsyncSubject | Only the last data is received |
ReplaySubject | Receive all data before and after subscription |
SerializedSubject | A thread-safe Subject, which can be converted from another Subject by calling toSerialized |
Common operators
type | operator |
---|---|
create type | create 、just 、timer 、interval 、from 、error |
conversion type | map 、flatMap 、concatMap 、switchMap 、buffer |
filter type | filter 、ofType 、debounce 、throttleWithTimeout 、distinct 、distinctUntilChanged 、first 、last 、take 、skip |
combination type | merge 、zip 、combineLatest |
error handling type | retry 、onErrorResumeNext |
Auxiliary Action Type | delay 、subscribeOn 、do 、to 、timeout |
Conditions and Boolean Types | amb 、contains 、takeUntil 、skipUntil |
Arithmetic and Aggregate Types | reduce 、max 、min 、sum |
Scheduler
type | describe |
---|---|
Schedulers.io | Cache thread pool, infinite number of threads, used for I/O operations |
Schedulers.computation | Fixed thread pool, the size is the number of CPU cores, for CPU-intensive computing (non-blocking) |
Schedulers.single | single thread pool |
Schedulers.newThread | Start a new thread for the specified task |
Schedulers.trampoline | When other queued tasks are completed, start execution in the current thread queue |
Schedulers.from | Use the specified Executor as the scheduler |
AndroidSchedulers.mainThread | Android'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]
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。