-
Notifications
You must be signed in to change notification settings - Fork 15
Conversation
If you mean within this PR it's already done when you squash, just edit the message from here. If you mean from the master history then I don't think so because we would need to rewrite history by force-pushing, which would mean anyone with the branch might have conflicts. |
@aballano that's not what I meant. Not sure how I can reflect that change properly in git. I retried with intermediate commits but got the same history. Not critical, so ready for review. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't say all that much about the code. Looks good though ^^
There are however a few nits on the documentation, which other than those reads quite well 👍
Oh btw is it possible to support bulk operations like |
Yes, we definitely can but I haven't attempted to implement them yet. |
@1Jajen1 what behavior would you expect for the different backpressure strategies? I think the one described below would be quite easy to add. offerAll(la: Iterable): Kind<F, Unit>
tryOfferAll(la: Iterable): Kind<F, Boolean>Works same as other flushAll(): Kind<F, List>For all strategies returns what is currently in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doc suggestions!!
I'd expect it to work as if we'd repeat Guessing from how the strategies currently work what you suggested should be the same right? The same cannot really hold for |
Right, that's exactly what I was thinking. So no need to implement anything low level, I'll add these as derived methods to |
That depends, are these methods supposed to be atomic? Or better put does this hold: Your name suggestions (missed them the first time) also make sense: |
Shouldn't be too hard to implement atomically. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the extensive review @1Jajen1!!! 🙏 👏 I'll be addressing the PR comments today, and I'll improve the test suite based on your suggestions!
"$label - empty queue takeAll is empty" { | ||
forAll(Gen.positiveIntegers()) { n -> | ||
IO.fx { | ||
val q = !queue(n) | ||
!q.takeAll() | ||
}.equalUnderTheLaw(IO.just(emptyList()), EQ()) | ||
} | ||
} | ||
|
||
"$label - empty queue peekAll is empty" { | ||
forAll(Gen.positiveIntegers()) { n -> | ||
IO.fx { | ||
val q = !queue(n) | ||
!q.peekAll() | ||
}.equalUnderTheLaw(IO.just(emptyList()), EQ()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh cool Github marks the range of your comments "Comment on lines +93 to +107" 😍
But this only makes sense if you can verify that it generated at least one empty queue (you'd have to generate lists of ints in that case).
All these queues
are empty, I'll update for more clarity but n
here is the capacity of the Queue
.
} | ||
} | ||
|
||
"$label - can take and offer at capacity" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What we're testing here is that you can tryOfferAll
2 items for a dropping queue with capacity 1 and 1 taker.
Without the taker being registered, tryOfferAll
would have to drop one of the items offered and thus tryOfferAll
would fail and return false
.
Co-Authored-By: Alberto Ballano <aballano@users.noreply.github.com> Co-Authored-By: Jannis <overesch.jannis@gmail.com>
@@ -67,13 +67,13 @@ interface Dequeue<F, A> { | |||
fun peekAll(): Kind<F, List<A>> | |||
} | |||
|
|||
/** A polymoprhic effect typeclass that allows [Dequeue]'ing values from a [Queue]. */ | |||
/** A polymorphic effect typeclass that allows [Enqueue]'ing values from a [Queue]. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** A polymorphic effect typeclass that allows [Enqueue]'ing values from a [Queue]. */ | |
/** A polymorphic effect typeclass that allows [Enqueue]'ing values to a [Queue]. */ |
Missed that on the first read through
@1Jajen1 after some discussion with @raulraja I decided we should not expose It's not a pattern we follow in the other concurrency primitives, nor is it a pattern that we actively support. Which is exceptions for control flow, in this case cancelation flow. On top of that Arrow Fx offers automatic cancelation support, and powerful combinators to prevent cancelation breaking and leaking to occur. So we should stay close to that. Additionally, we can always come back to this and add EDIT: not all tests descriptions you gave were clear to me, but this should now cover all behavior I believe. Please also review the docs again, I added some more documentation. cc\ @aballano. |
Saw a test failing in between commits, might be flaky
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nits 🎉 😄
if (take != null) later { take(value) }.map { true } | ||
else just(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (take != null) later { take(value) }.map { true } | |
else just(true) | |
take?.let { later { take(value) }.map { true } } ?: just(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't find ?:
clearer than if-else
expression here.
* [Surplus]: Contains a queue of values and two maps of registered id & offer/shutdown callbacks waiting to | ||
* offer once there is room (if the queue is bounded, dropping or sliding). | ||
* | ||
* [Shutdown]: Holds no values, an offer or take in Shutdown state creates a QueueShutdown error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this case missing? and QueueShutdown
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed shutdown
support, thanks for noticing!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave a look at the tests and they look good IMO
@@ -14,6 +22,18 @@ import io.kotlintest.shouldNot | |||
fun <A> A.equalUnderTheLaw(b: A, eq: Eq<A>): Boolean = | |||
shouldBeEq(b, eq).let { true } | |||
|
|||
fun <A> IOOf<A>.equalUnderTheLaw(b: IOOf<A>, EQA: Eq<A> = Eq.any(), timeout: Duration = 5.seconds): Boolean = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this explicit equalUnderTheLaw
? Cannot we test like before using the one above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's for a proper assertion message. The one implement through IO.toString
is not very meaningful.
Co-Authored-By: danieh <danimontoya_86@hotmail.com>
This PR exposes the new APIs from Queue, peek and try that do not block.
It also includes additional docs and tests for the new APIs, and a small restructuring.
It seems I have incorrectly merged ConcurrentQueue with CancelableQueue tho.
Any1 any idea how I keep the git history correctly? I'd happily re-open a new PR.