kandi background
Explore Kits

RxJavaSamples | RxJava 2 和 Retrofit 结合使用的几个最常见使用方式举例 | Reactive Programming library

 by   rengwuxian Java Version: 2.0 License: No License

 by   rengwuxian Java Version: 2.0 License: No License

Download this library from

kandi X-RAY | RxJavaSamples Summary

RxJavaSamples is a Java library typically used in Programming Style, Reactive Programming applications. RxJavaSamples has no vulnerabilities, it has build file available and it has medium support. However RxJavaSamples has 6 bugs. You can download it from GitHub.
RxJava 2 和 Retrofit 结合使用的几个最常见使用方式举例
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • RxJavaSamples has a medium active ecosystem.
  • It has 3974 star(s) with 880 fork(s). There are 153 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 22 open issues and 2 have been closed. On average issues are closed in 740 days. There are no pull requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of RxJavaSamples is 2.0
RxJavaSamples Support
Best in #Reactive Programming
Average in #Reactive Programming
RxJavaSamples Support
Best in #Reactive Programming
Average in #Reactive Programming

quality kandi Quality

  • RxJavaSamples has 6 bugs (1 blocker, 0 critical, 3 major, 2 minor) and 32 code smells.
RxJavaSamples Quality
Best in #Reactive Programming
Average in #Reactive Programming
RxJavaSamples Quality
Best in #Reactive Programming
Average in #Reactive Programming

securitySecurity

  • RxJavaSamples has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • RxJavaSamples code analysis shows 0 unresolved vulnerabilities.
  • There are 10 security hotspots that need review.
RxJavaSamples Security
Best in #Reactive Programming
Average in #Reactive Programming
RxJavaSamples Security
Best in #Reactive Programming
Average in #Reactive Programming

license License

  • RxJavaSamples does not have a standard license declared.
  • Check the repository for any license declaration and review the terms closely.
  • Without a license, all rights are reserved, and you cannot use the library in your applications.
RxJavaSamples License
Best in #Reactive Programming
Average in #Reactive Programming
RxJavaSamples License
Best in #Reactive Programming
Average in #Reactive Programming

buildReuse

  • RxJavaSamples releases are available to install and integrate.
  • Build file is available. You can build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
  • RxJavaSamples saves you 703 person hours of effort in developing the same functionality from scratch.
  • It has 1625 lines of code, 74 functions and 46 files.
  • It has low code complexity. Code complexity directly impacts maintainability of the code.
RxJavaSamples Reuse
Best in #Reactive Programming
Average in #Reactive Programming
RxJavaSamples Reuse
Best in #Reactive Programming
Average in #Reactive Programming
Top functions reviewed by kandi - BETA

kandi has reviewed RxJavaSamples and discovered the below as its top functions. This is intended to give you an instant insight into RxJavaSamples implemented functionality, and help decide if they suit your requirements.

  • Upload the fake data
  • Initialize the activity .
  • Subscribe items to a list of items .
  • Get the fake data for a given user
  • Loads a page of the map .
  • Get a list of images from the gank result .
  • Search for images in the browser .
  • Write a list of items to a json file
  • Get zhuang api api .
  • helper method to set the description

RxJavaSamples Key Features

基本使用 实现最基本的网络请求和结果处理。 ![screenshot_1](./images/screenshot_1.png)

转换(map) 把返回的数据转换成更方便处理的格式再交给 Observer。 ![screenshot_2](./images/screenshot_2.png)

压合(zip) 将不同接口并行请求获取到的数据糅合在一起后再处理。 ![screenshot_3](./images/screenshot_3.png)

一次性 token 需要先请求 token 再访问的接口,使用 flatMap() 将 token 的请求和实际数据的请求连贯地串起来,而不必写嵌套的 Callback 结构。 ![screenshot_4](./images/screenshot_4.png)

非一次性 token 对于非一次性的 token (即可重复使用的 token),在获取 token 后将它保存起来反复使用,并通过 retryWhen() 实现 token 失效时的自动重新获取,将 token 获取的流程彻底透明化,简化开发流程。 ![screenshot_5](./images/screenshot_5.png)

缓存 使用 BehaviorSubject 缓存数据。 ![screenshot_6](./images/screenshot_6.png)

default

copy iconCopydownload iconDownload
实现最基本的网络请求和结果处理。
![screenshot_1](./images/screenshot_1.png)

Receiving items in onNext() after calling dispose() in RxJava

copy iconCopydownload iconDownload
val compositeDisposable = CompositeDisposable()
    compositeDisposable.add(
            Observable
                    .create { e: ObservableEmitter<String> ->
                        val worker = Schedulers.io().createWorker()
                        e.setDisposable(worker)
                        worker.schedule {
                            for (i in 1..5) {
                                if (i == 3) {
                                    compositeDisposable.dispose() //changed here
                                }
                                e.onNext("Event $i on thread ${Thread.currentThread().name}")
                            }
                        }

                    }
                    .subscribe(
                            { s ->
                                Log.d(TAG, "createObservableWithDisposable onNext msg=$s")
                            },
                            { e ->
                                Log.d(TAG, "createObservableWithDisposable", e)
                            },
                            {
                                Log.d(TAG, "createObservableWithDisposable onComplete")
                            }

                    )
    )

Community Discussions

Trending Discussions on RxJavaSamples
  • Receiving items in onNext() after calling dispose() in RxJava
Trending Discussions on RxJavaSamples

QUESTION

Receiving items in onNext() after calling dispose() in RxJava

Asked 2019-Feb-25 at 06:00

This is what I read about dispose() here:

In a nutshell, when the Disposable (which is implemented by the TestObserver) gets disposed, the Observer (also TestObserver) will no longer receive values from the Observable.

Here is my code:

private fun createObservableWithDisposable() {
    Observable
            .create { e: ObservableEmitter<String> ->
                val worker = Schedulers.io().createWorker()
                e.setDisposable(worker)
                worker.schedule {
                    for (i in 1..5) {
                        if (i == 3) {
                            worker.dispose()
                            // https://medium.com/@vanniktech/rxjava-2-disposable-under-the-hood-f842d2373e64
                            // After calling dispose(), the subscriber no longer receives items passed in OnNext().
                            // But it doesn't work in my code
                        }
                        e.onNext("Event $i on thread ${Thread.currentThread().name}")
                    }
                }
            }
            .subscribe(
                    { s ->
                        Log.d(TAG, "createObservableWithDisposable onNext msg=$s")
                    },
                    { e ->
                        Log.d(TAG, "createObservableWithDisposable", e)
                    },
                    {
                        Log.d(TAG, "createObservableWithDisposable onComplete")
                    }
            )
}

And this is what I see in Logcat:

2019-02-25 08:10:53.414 12071-12101/ru.sample D/RxJavaSamples: createObservableWithDisposable onNext msg=Event 1 on thread RxCachedThreadScheduler-1
2019-02-25 08:10:53.414 12071-12101/ru.sample D/RxJavaSamples: createObservableWithDisposable onNext msg=Event 2 on thread RxCachedThreadScheduler-1
2019-02-25 08:10:53.414 12071-12101/ru.sample D/RxJavaSamples: createObservableWithDisposable onNext msg=Event 3 on thread RxCachedThreadScheduler-1
2019-02-25 08:10:53.414 12071-12101/ru.sample D/RxJavaSamples: createObservableWithDisposable onNext msg=Event 4 on thread RxCachedThreadScheduler-1
2019-02-25 08:10:53.414 12071-12101/ru.sample D/RxJavaSamples: createObservableWithDisposable onNext msg=Event 5 on thread RxCachedThreadScheduler-1

I expected to see only the first two emissions. I.e., I thought that after calling dispose() onNext() won't be called.

ANSWER

Answered 2019-Feb-25 at 06:00

you disposed worker which had been providing items, not subscriber.

To stop receiving items, try to

val compositeDisposable = CompositeDisposable()
    compositeDisposable.add(
            Observable
                    .create { e: ObservableEmitter<String> ->
                        val worker = Schedulers.io().createWorker()
                        e.setDisposable(worker)
                        worker.schedule {
                            for (i in 1..5) {
                                if (i == 3) {
                                    compositeDisposable.dispose() //changed here
                                }
                                e.onNext("Event $i on thread ${Thread.currentThread().name}")
                            }
                        }

                    }
                    .subscribe(
                            { s ->
                                Log.d(TAG, "createObservableWithDisposable onNext msg=$s")
                            },
                            { e ->
                                Log.d(TAG, "createObservableWithDisposable", e)
                            },
                            {
                                Log.d(TAG, "createObservableWithDisposable onComplete")
                            }

                    )
    )

Source https://stackoverflow.com/questions/54857912

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install RxJavaSamples

You can download it from GitHub.
You can use RxJavaSamples like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the RxJavaSamples component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Share this Page

share link
Consider Popular Reactive Programming Libraries
Compare Reactive Programming Libraries with Highest Support
Compare Reactive Programming Libraries with Highest Quality
Compare Reactive Programming Libraries with Highest Security
Compare Reactive Programming Libraries with Permissive License
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.