ReactiveX / RxKotlin

RxJava bindings for Kotlin
Apache License 2.0
7.04k stars 454 forks source link

[Enhancement] Could you provide “CoroutineScheduler” feature? #211

Closed Guang1234567 closed 5 years ago

Guang1234567 commented 5 years ago

Hello dev:

I just want some "rx-kotlin-coroutine" feature that like rxandroid.

Could you consider about this feature? thx.

eg:


public final class CoroutineSchedulers {

    /** A {@link Scheduler} which executes actions on {@code CoroutineScope}. */
    public static Scheduler from(CoroutineScope scope) {
        //...
    }

     /** A {@link Scheduler} which executes actions on {@code Dispatcher}. */
     public static Scheduler from(Dispatcher dispatcher) {
        //...
    }
}

so we can


class MainActivity : AppCompatActivity(), CoroutineScope {

    override val coroutineContext: CoroutineContext
        get() = Dispatchers.Main + job

    private lateinit var job: Job

    override fun onCreate(savedInstanceState: Bundle?) {
             super.onCreate(savedInstanceState)
             job = Job()

            RxView.onClick(btnABC).
                 .observeOn(CoroutineSchedulers.from(this))  // The stream will be complete when the `job.cancel()` was called in `onDestroy()`
                .takeUntil(…)   // or takeUntil after `job.cancel` was called? Maybe  it similar to RxLifecycle
                 .subscribe(...)
       }

    override fun onDestroy() {
            job.cancel()
            super.onDestroy()
    }

}
JakeWharton commented 5 years ago

Why does that belong here and not in the couroutine Rx library that's part of couroutines.

On Sun, Mar 3, 2019, 10:15 AM GuangGuang <notifications@github.com wrote:

Hello dev:

I just want some "rx-kotlin-coroutine https://github.com/hltj/kotlinx.coroutines-cn" feature that like rxandroid https://github.com/ReactiveX/RxAndroid/blob/e58f44d8842c082698c1b5e3d367f805b95d8509/rxandroid/src/main/java/io/reactivex/android/schedulers/AndroidSchedulers.java#L46

eg:

public final class CoroutineSchedulers {

/** A {@link Scheduler} which executes actions on {@code CoroutineScope}. */

public static Scheduler from(CoroutineScope stop) {

    //...

}

 /** A {@link Scheduler} which executes actions on {@code Dispatcher}. */

 public static Scheduler from(Dispatcher dispatcher) {

    //...

}

}

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ReactiveX/RxKotlin/issues/211, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEVgB-d_Asovsb2-yjedIGLb-z1KPks5vS-cUgaJpZM4bbC9h .

Guang1234567 commented 5 years ago

@JakeWharton

You are right! It is belong to kotlinx-coroutines-rx2.

so close this issue.