-
Notifications
You must be signed in to change notification settings - Fork 525
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
Decide what we're going to do with Resource#parZip #1576
Comments
Why does |
I kinda would have expected the Parallel newtypes to be CommutativeApplicative, and that, for Resource, order of finalisation is part of equivalence, which make sequential release on Validated breaks the CommutativeApplicative assumption admittedly , but I think not having resources released in parallel actually has practical consequences and breaks the principle of least surprise |
I agree with the commutative applicative argument. It's also worth noting that Validated does work here so long as the inner E forms a commutative monoid. But at any rate… What I don't see is how to make this happen with Resource without bespoke overrides, which make me nervous in this case. The problem is that we flatMap inside Fiber#joinWith, and we don't have any knowledge of the other fibers when we do so. Even if we did have knowledge of the other fibers, it's not at all clear to me that we could get the finalizers to run in parallel with Resource specifically. What is it about Resource in particular which gives rise to this property? In abstract, I mean. Are we not likely to see other effects with the same issue in Parallel? |
In light of everything with |
it still sounds very very weird to me |
I agree in a vacuum that parallel finalization makes sense, but I don't see a way that it can be derived from the more primitive semantics without totally special-casing this one specific scenario. It's basically like the whole |
there is another scarier possibility, which is that the primitive semantics of In this case, not only we have the specific vs general, but also the fact that Resource.Par being commutative is really the only meaningful semantics, and having Also, more worryingly, this is happening essentially at the first layer we are exploiting Also, we don't generally propose abstracting over |
Except literally no other (IO.raiseError(e1), IO.raiseError(e2)).parTupled Commutativity just isn't a guarantee we have in this space. It's roughly intuitive, but it's also just not achievable unless the underlying And this is the crux of the issue. We have an intuition that So basically what I'm saying is that intuition is what's wrong, and Cats Effect is showing us that. |
this is commutative though, no? (although you are unlikely to observe it), but I think you have a strong argument, and we can discard commutativity from the discussion (e.g However, I think we both agree that concurrent release is preferable if you think about In other words: many more users will care about Resource.both not closing in parallel, than about the fact that |
If we view the parallel release semantics as an optimization and implementation detail of a very common case, rather than as something that's fundamentally dictated by the model, then I'm completely okay with it. :-) That would imply that what I mentioned on #1652 was slightly backwards: we should override |
It's somewhat redundant with
both
(defined inConcurrent
) now, though it is probably slightly faster. The real problem though is thatparZip
is actually inconsistent withboth
in that it runs finalizers in parallel, whereasboth
runs them sequentially.The text was updated successfully, but these errors were encountered: