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

Prototype context receivers #463

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,36 @@ import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlin.coroutines.CoroutineContext

/** Extension that proxies to the normal [autoDispose] extension function with a [ScopeProvider]. */
context(CoroutineScope)
public inline fun <T : Any> Flowable<T>.autoDispose(): FlowableSubscribeProxy<T> {
return autoDispose(asScopeProvider())
}

/** Extension that proxies to the normal [autoDispose] extension function with a [ScopeProvider]. */
context(CoroutineScope)
public inline fun <T : Any> Observable<T>.autoDispose(): ObservableSubscribeProxy<T> {
return autoDispose(asScopeProvider())
}

/** Extension that proxies to the normal [autoDispose] extension function with a [ScopeProvider]. */
context(CoroutineScope)
public inline fun <T : Any> Single<T>.autoDispose(): SingleSubscribeProxy<T> {
return autoDispose(asScopeProvider())
}

/** Extension that proxies to the normal [autoDispose] extension function with a [ScopeProvider]. */
context(CoroutineScope)
public inline fun <T : Any> Maybe<T>.autoDispose(): MaybeSubscribeProxy<T> {
return autoDispose(asScopeProvider())
}

/** Extension that proxies to the normal [autoDispose] extension function with a [ScopeProvider]. */
context(CoroutineScope)
public inline fun Completable.autoDispose(): CompletableSubscribeProxy {
return autoDispose(asScopeProvider())
}

/** Extension that proxies to the normal [autoDispose] extension function with a [ScopeProvider]. */
public inline fun <T : Any> Flowable<T>.autoDispose(scope: CoroutineScope): FlowableSubscribeProxy<T> {
return autoDispose(scope.asScopeProvider())
Expand Down
10 changes: 5 additions & 5 deletions autodispose/src/test/java/autodispose2/AutoDisposeKotlinTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -444,15 +444,15 @@ class AutoDisposeKotlinTest {
o.takeSubscribe()

assertThat(source.hasObservers()).isTrue()
assertThat(scopeSource.hasObservers())
assertThat(scopeSource.hasObservers()).isTrue()

source.onNext(1)
assertThat(o.takeNext()).isEqualTo(1)

source.onNext(2)

assertThat(source.hasObservers()).isTrue()
assertThat(scopeSource.hasObservers())
assertThat(scopeSource.hasObservers()).isTrue()
assertThat(o.takeNext()).isEqualTo(2)

scopeSource.onComplete()
Expand All @@ -474,7 +474,7 @@ class AutoDisposeKotlinTest {
o.takeSubscribe()

assertThat(source.hasObservers()).isTrue()
assertThat(scopeSource.hasObservers())
assertThat(scopeSource.hasObservers()).isTrue()

scopeSource.onComplete()

Expand All @@ -498,7 +498,7 @@ class AutoDisposeKotlinTest {
o.takeSubscribe()

assertThat(source.hasObservers()).isTrue()
assertThat(scopeSource.hasObservers())
assertThat(scopeSource.hasObservers()).isTrue()

scopeSource.onComplete()

Expand All @@ -522,7 +522,7 @@ class AutoDisposeKotlinTest {
o.takeSubscribe()

assertThat(source.hasObservers()).isTrue()
assertThat(scopeSource.hasObservers())
assertThat(scopeSource.hasObservers()).isTrue()

scopeSource.onComplete()

Expand Down
9 changes: 6 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ subprojects {
kotlinOptions {
freeCompilerArgs = [
"-Xjsr305=strict",
"-progressive"
"-progressive",
"-Xcontext-receivers"
]
jvmTarget = "1.8"
}
Expand All @@ -167,7 +168,8 @@ subprojects {
kotlinOptions {
freeCompilerArgs = [
"-Xjsr305=strict",
"-progressive"
"-progressive",
"-Xcontext-receivers"
]
jvmTarget = "1.8"
}
Expand All @@ -176,7 +178,8 @@ subprojects {
kotlinOptions {
freeCompilerArgs = [
"-Xjsr305=strict",
"-progressive"
"-progressive",
"-Xcontext-receivers"
]
jvmTarget = "1.8"
}
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ android.defaults.buildfeatures.renderscript=false
android.defaults.buildfeatures.resvalues=false
android.defaults.buildfeatures.shaders=false
android.library.defaults.buildfeatures.androidresources=false
android.disableAutomaticComponentCreation=true

kapt.include.compile.classpath=false

Expand Down
10 changes: 5 additions & 5 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ def versions = [
androidTest: '1.4.0',
animalSniffer: '1.5.0',
androidxLifecycle: '2.3.1',
dokka: '1.5.0',
dokka: '1.6.10',
errorProne: '2.9.0',
errorPronePlugin: '2.0.1',
gjf: '1.11.0',
nullawayPlugin: '1.1.0',
kotlin: '1.5.30',
lint: '30.0.0',
kotlin: '1.6.20-M1',
lint: '30.1.0',
ktlint: '0.42.1',
spotless: '5.14.3'
spotless: '6.2.1'
]

def apt = [
Expand All @@ -49,7 +49,7 @@ def build = [
animalSniffer: 'org.codehaus.mojo.signature:java17:1.0@signature',

gradlePlugins: [
android: 'com.android.tools.build:gradle:7.0.0',
android: 'com.android.tools.build:gradle:7.1.0',
dokka: "org.jetbrains.dokka:dokka-gradle-plugin:${versions.dokka}",
dokkaAndroid: "org.jetbrains.dokka:dokka-android-gradle-plugin:${versions.dokka}",
kotlin: "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists