Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Outstanding dequeues not completed on tryOffer1 #246

Merged
merged 1 commit into from Aug 7, 2020
Merged

Conversation

nomisRev
Copy link
Member

@nomisRev nomisRev commented Aug 7, 2020

The update function in PubSub was not correctly invoking the completion for outstanding dequeues.

To fix this I replaced the usages of Promise to UnsafePromise so we can complete the promises in a non-suspending manner. This allows for both modify and update which can modify the state with suspend, and non-suspend support.

@@ -79,15 +78,15 @@ internal interface Subscribe<A, Selector> {

internal interface PubSub<I, O, Selector> : Publish<I>, Subscribe<O, Selector> {

data class Publisher<A>(val token: Token, val i: A, val signal: Promise<Unit>) {
suspend fun complete(): Unit {
ForkConnected { signal.complete(Unit) }
Copy link
Member Author

Choose a reason for hiding this comment

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

It's not necessary to launch completion in a Fiber since the join operations already intercept before returning, meaning they always get properly re-scheduled before returning from join.

Pair(ps2, result)
}
val (ps2, action) = loop(ps1) { Unit }
Pair(ps2, { action.invoke(); result })
Copy link
Member Author

Choose a reason for hiding this comment

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

This was the bug fix, in case an outstanding offer was found. Its completion needs to be invoked.

@@ -659,13 +658,13 @@ internal class DefaultPubSub<I, O, QS, S>(private val strategy: PubSub.Strategy<
*/
private tailrec fun loop(
ps: PubSub.PubSubState<I, O, QS, S>,
action: suspend () -> Unit
): Pair<PubSub.PubSubState<I, O, QS, S>, (suspend () -> Unit)> {
Copy link
Member Author

Choose a reason for hiding this comment

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

The actions running in the loop no longer need to be suspending since we rely on UnsafePromise for signaling.

Instead the functionality of suspend is exposed through the modify operator.

Copy link
Contributor

@danimontoya danimontoya left a comment

Choose a reason for hiding this comment

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

great!! thank you @nomisRev !! 🙌

@nomisRev nomisRev merged commit 882b650 into master Aug 7, 2020
@nomisRev nomisRev deleted the sv-queue-fix branch August 7, 2020 11:52
@nomisRev nomisRev restored the sv-queue-fix branch August 7, 2020 11:52
@nomisRev nomisRev deleted the sv-queue-fix branch August 7, 2020 11:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants