Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@adamgfraser
Copy link
Contributor

I don't think this test is quite correctly specified.

The semantics of flatMapParSwitch are that it is supposed to maintain the target parallelism but unlike flatMapPar, which would wait for the previous child streams to complete before opening new ones, it should interrupt the oldest child stream to allow a new one to be opened while maintaining the target parallelism.

In this test we are creating 12 child streams with flatMapParSwitch with a parallelism of 4. The first 8 never complete and the last 4 increment a Ref. So we are testing that the first 8 child streams will be terminated and that the last four complete.

However, if one of the last four child streams completes before all of them are opened then we don't actually need to terminate one of the previous child streams to maintain the target parallelism and could suspend indefinitely.

This doesn't actually occur today because the current implementation always terminates the oldest child stream when we open a new child stream, even if that is not necessary to stay within the bounded parallelism. However, at the very least this seems like a guarantee that should not be relied on so I don't think we should be testing for it.

Instead we can use a Promise to make sure that all four of the last child streams are open at the same time, which would require closing all of the other child streams.

@adamgfraser adamgfraser requested review from jdegoes and vigoo March 10, 2023 21:29
@jdegoes jdegoes merged commit f6ef824 into zio:series/2.x Mar 10, 2023
@adamgfraser adamgfraser deleted the flatmapparswitch branch March 10, 2023 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants