Skip to content

Commit

Permalink
Issue bumble-tech#296 Dispose NodeConnector intake in onDestroy
Browse files Browse the repository at this point in the history
  • Loading branch information
LachlanMcKee committed Dec 4, 2022
1 parent e636b6b commit d4da1b5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Pending changes

- [#296](https://github.com/bumble-tech/appyx/issues/296)**Fixed**: `NodeConnector.intake` is now disposed when a `Node` is destroyed.

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.bumble.appyx.core.lifecycle.subscribe
import com.jakewharton.rxrelay2.PublishRelay
import com.jakewharton.rxrelay2.Relay
import io.reactivex.Observer
import io.reactivex.disposables.Disposable

class NodeConnector<Input, Output>(
override val input: Relay<Input> = PublishRelay.create(),
Expand All @@ -15,6 +16,7 @@ class NodeConnector<Input, Output>(
private val exhaust: Relay<Output> = PublishRelay.create()
private var isFlushed = false
private val outputCache = mutableListOf<Output>()
private var intakeDisposable: Disposable? = null

override val output: Relay<Output> = object : Relay<Output>() {

Expand All @@ -31,7 +33,7 @@ class NodeConnector<Input, Output>(
}

override fun onCreate(lifecycle: Lifecycle) {
lifecycle.subscribe(onCreate = { flushOutputCache() })
lifecycle.subscribe(onCreate = { flushOutputCache() }, onDestroy = { intakeDisposable?.dispose() })
}

private val cacheSubscription = intake.subscribe {
Expand All @@ -55,7 +57,7 @@ class NodeConnector<Input, Output>(
}

private fun switchToExhaust() {
intake.subscribe { exhaust.accept(it) }
intakeDisposable = intake.subscribe { exhaust.accept(it) }
cacheSubscription.dispose()
}
}

0 comments on commit d4da1b5

Please sign in to comment.