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

MVICore RxJava3 update #198

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
detekt fixed
  • Loading branch information
SerhiiDenysov committed Sep 13, 2024
commit 73878e6d1e37c9d5312ef2cbc9d399443462d997
2 changes: 1 addition & 1 deletion binder/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<CurrentIssues>
<ID>MaxLineLength:Connection.kt$infix</ID>
<ID>MaxLineLength:ManualLifecycle.kt$ManualLifecycle$class</ID>
<ID>ReturnCount:Consumer.kt$fun &lt;In> Consumer&lt;In>.wrapWithMiddleware( standalone: Boolean = true, name: String? = null, postfix: String? = null, wrapperOf: Any? = null ): Consumer&lt;In></ID>
<ID>ReturnCount:Consumer.kt$fun &lt;In : Any> Consumer&lt;In>.wrapWithMiddleware( standalone: Boolean = true, name: String? = null, postfix: String? = null, wrapperOf: Any? = null ): Consumer&lt;In></ID>
<ID>TooManyFunctions:Binder.kt$Binder : Disposable</ID>
<ID>UseCheckOrError:StandaloneMiddleware.kt$StandaloneMiddleware$throw IllegalStateException("Middleware was initialised in standalone mode, can't accept other connections")</ID>
</CurrentIssues>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,34 +114,33 @@ class MemoryRecordStore(
throw IllegalStateException("Trying to playback while still recording")
}

cachedEvents.keys
val firstKey = cachedEvents.keys
.first { it.id == recordKey.id }
.let { key ->
cachedEvents[key]?.let { event ->
Observable.fromIterable(event)
.delay { Observable.timer(it.delayNanos, TimeUnit.NANOSECONDS) }
.observeOn(playbackScheduler)
.doOnNext { logger?.invoke("MemoryRecordStore: PLAYBACK: ts: ${it.delayNanos}, event: ${it.obj}") }
.map { it.obj }
.doOnSubscribe {
state.onNext(PLAYBACK)
key.middleWare.startPlayback()
}
.doOnTerminate {
logger?.invoke("MemoryRecordStore: PLAYBACK FINISHED")
state.onNext(FINISHED_PLAYBACK)
state.onNext(IDLE)
key.middleWare.stopPlayback()
}
.subscribe {
key.middleWare.replay(
// restore last state before playback started if needed
if (it == EndSignal) lastElementBuffer[key]
else it
)
}
val event = cachedEvents[firstKey]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this always works?

Copy link
Collaborator

@CherryPerry CherryPerry Sep 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it is a good question. But it is true for the previous implementation too.

.let { key ->
  Observable.fromIterable(cachedEvents[key])
  ...
}

RxJava2 version does not have @NonNull annotation, so Kotlin compiler allows passing a nullable value here, while it will still throw an exception in runtime.

RxJava3 version now has @NonNull annotation, so Kotlin compiler is more strict here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt it worked fine in the previous version as well. Because the result of the subscription is not used anywhere, hence there’s no manual unsubscribe implemented.

if (event != null) {
Observable.fromIterable(event)
.delay { Observable.timer(it.delayNanos, TimeUnit.NANOSECONDS) }
.observeOn(playbackScheduler)
.doOnNext { logger?.invoke("MemoryRecordStore: PLAYBACK: ts: ${it.delayNanos}, event: ${it.obj}") }
.map { it.obj }
.doOnSubscribe {
state.onNext(PLAYBACK)
firstKey.middleWare.startPlayback()
}
}
.doOnTerminate {
logger?.invoke("MemoryRecordStore: PLAYBACK FINISHED")
state.onNext(FINISHED_PLAYBACK)
state.onNext(IDLE)
firstKey.middleWare.stopPlayback()
}
.subscribe {
firstKey.middleWare.replay(
// restore last state before playback started if needed
if (it == EndSignal) lastElementBuffer[firstKey]
else it
)
}
}
}

private data class Key<Out : Any, In : Any>(
Expand Down
Loading