Skip to content

Commit

Permalink
Use Kotlin features
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Jan 24, 2025
1 parent e070510 commit 9621865
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## [Unreleased]
### Changed
- **BREAKING** Replace `RxJava Disposable` with `Kotlin Job`, and remove `rxjava` completely. ([#10](https://github.com/diffplug/durian-rx/pull/10))
- Add strict nullability to RxBox and improve efficiency. ([#12](https://github.com/diffplug/durian-rx/pull/12))
- Replace `RxJava Disposable` with `Kotlin Job`, and remove `rxjava` completely. ([#10](https://github.com/diffplug/durian-rx/pull/10))
- Bump required java from 11 to 17. ([#9](https://github.com/diffplug/durian-rx/pull/9))

## [4.0.1] - 2022-12-20
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/diffplug/common/rx/GuardedExecutor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import java.util.concurrent.Executor
import java.util.function.Supplier
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.Flow

/**
Expand All @@ -33,12 +32,11 @@ import kotlinx.coroutines.flow.Flow
*/
open class GuardedExecutor(val delegate: RxExecutor, val guard: Chit) : Executor, RxSubscriber {
override fun execute(command: Runnable) {
delegate.executor().execute(guard.guard(command))
delegate.executor.execute(guard.guard(command))
}

/** Creates a runnable which runs on this Executor iff the guard widget is not disposed. */
fun wrap(delegate: Runnable): Runnable {
Objects.requireNonNull(delegate)
return Runnable { execute(guard.guard(delegate)) }
}

Expand All @@ -48,7 +46,7 @@ open class GuardedExecutor(val delegate: RxExecutor, val guard: Chit) : Executor
guard.runWhenDisposed { job.cancel() }
job
} else {
SupervisorJob().apply { cancel() }
Rx.sentinelJob
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/main/java/com/diffplug/common/rx/RxExecutor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,13 @@ import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch

class RxExecutor
internal constructor(private val executor: Executor, val dispatcher: CoroutineDispatcher) :
class RxExecutor internal constructor(val executor: Executor, val dispatcher: CoroutineDispatcher) :
RxSubscriber {

interface Has : Executor {
val rxExecutor: RxExecutor
}

fun executor() = executor

override fun <T> subscribe(flow: Flow<T>, listener: RxListener<T>) {
subscribeDisposable(flow, listener)
}
Expand Down

0 comments on commit 9621865

Please sign in to comment.