Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context receiver APIs #370

Open
ZacSweers opened this issue Sep 6, 2019 · 4 comments
Open

Context receiver APIs #370

ZacSweers opened this issue Sep 6, 2019 · 4 comments

Comments

@ZacSweers
Copy link
Collaborator

If compound extensions do make their way into Kotlin, we could leverage them nicely in AutoDispose to do something like this:

fun <T> ScopeProvider.Observable<T>.autoDispose() {
  // ...
}

fun test(scope: ScopeProvider) = scope.apply {
  myObservable
      .autoDisposable()
      .subscribe()
}

// or

class Worker : ScopeProvider {
  fun run() {
    workObservable
        .autoDisposable()
        .subscribe()
  }
}
@ZacSweers
Copy link
Collaborator Author

Note: this would supersede the need for #375

@ZacSweers
Copy link
Collaborator Author

Closing this as it seems like it's not moving anywhere

@ZacSweers
Copy link
Collaborator Author

context receivers are happening

@ZacSweers ZacSweers reopened this Feb 13, 2022
@ZacSweers ZacSweers changed the title Compound extension APIs Context receiver APIs Feb 13, 2022
@psteiger
Copy link
Contributor

psteiger commented Mar 8, 2023

Should be a very simple function:

// Original function
@CheckReturnValue
inline fun <T> Observable<T>.autoDispose(provider: ScopeProvider): ObservableSubscribeProxy<T> =
    this.`as`(AutoDispose.autoDisposable(provider))

// Context receivers function
context(ScopeProvider)
inline fun <T> Observable<T>.autoDispose(): ObservableSubscribeProxy<T> = autoDispose(this@ScopeProvider)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants