Repository navigation
Zero-capacity channel - #1108
Conversation
| def empty()(using AllowUnsafe) = result(true) | ||
| def full()(using AllowUnsafe) = result(true) |
There was a problem hiding this comment.
That's correct though, isn't it?
There was a problem hiding this comment.
I think it is, yes. Just a bit ironic, as I generally would expect empty != full
| if result.contains(true) then flush() | ||
| result | ||
| end offer | ||
| def offer(value: A)(using AllowUnsafe) = result(false) |
There was a problem hiding this comment.
I think this behavior isn't ideal because there can be a pending take that could be satisfied. It seems we could just attempt to get a pending take from the queue?
There was a problem hiding this comment.
Oh right -- I meant to do that.
There was a problem hiding this comment.
Ok I added this update (along with others -- see resolved conversations). This is now breaking a bunch of tests. Do we want to revert or change tests to expect different behavior for the zero-capacity case?
There was a problem hiding this comment.
Could you elaborate on the behavior changes that break the tests?
There was a problem hiding this comment.
Current implementation of ZeroCapacityChannel#close always returns an empty backlog, since there's no queue, but since it's offer behavior is different, the accounting that's used in tests for comparing the backlog to what's been offered doesn't translate.
For instance, the test "offer and close" offers a bunch of values and expects to get everything that was successfully offered back when calling close(). A zero-capacity channel can successfully offer them, but returns none of them on close.
Basically any test that asserts on backlogs from close() either fail or are flaky. Some Hub tests are failing now too.
There was a problem hiding this comment.
It seems just a test issue? The behavior sounds ok to me
There was a problem hiding this comment.
Made backlog assertions conditional on channel size.
…separate classes with bath class
| discard(promise.complete(Result.unit)) | ||
| Absent | ||
| case Present(value) => | ||
| if batch.tail.nonEmpty then discard(puts.offer(Put.Batch(batch.tail, promise))) |
There was a problem hiding this comment.
This can break fairness since the batched put goes back to the end of the queue. It's pre-existing so we could follow up separately
| def loop(current: Chunk[A]): Result[Closed, Chunk[A]] = | ||
| val next = queue.drain() | ||
| final class NonZeroCapacityUnsafe[A]( | ||
| override val capacity: Int, |
There was a problem hiding this comment.
we need to specify the size of the queue
|
I think the latest updates address all PR review comments |
fwbrasil
left a comment
There was a problem hiding this comment.
LGTM besides the couple of comments
Addresses #987
Problem
Zero-capacity channels did not function properly since the default implementation expected to be able to offer to and pull from the intermediate queue directly.
Solution
Updated
Channel.Unsafe.initto return a separate implementation ofChannel.Unsafewhen_capacity == 0. This new implementation has noqueue. It's behavior is subtly different in the following ways:putsandtakesqueues directlyputsandtakesare both non-emptyNotes