<html><body><div id="zimbraEditorContainer" style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000" class="4"><div><br></div><div><br></div><hr id="zwchr" data-marker="__DIVIDER__"><div data-marker="__HEADERS__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>"Ron Pressler" <ron.pressler@oracle.com><br><b>To: </b>"Remi Forax" <forax@univ-mlv.fr><br><b>Cc: </b>"Alan Bateman" <alan.bateman@oracle.com>, "loom-dev" <loom-dev@openjdk.java.net><br><b>Sent: </b>Thursday, May 11, 2023 1:36:07 AM<br><b>Subject: </b>Re: Structured Concurrency yet again<br></blockquote></div><div data-marker="__QUOTED_TEXT__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;">
<br class="">
<div><br class="">
<blockquote class="">
<div class="">On 10 May 2023, at 17:46, <a href="mailto:forax@univ-mlv.fr" class="" target="_blank">
forax@univ-mlv.fr</a> wrote:</div>
<div class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Yes,
 but Go channels also do O(N) wakeups in the worst case (sometimes you can pump several results in one wakeup) and nobody complain.</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
</div>
</blockquote>
<div><br class="">
</div>
<div>Channels aren’t Go’s structured concurrency construct, errgroups are, and they block once (at least their API suggests that).</div></div></blockquote><div><br></div>Errgroup is a special construct that is the equivalent of STS.ShutdownOnFailure (you can also implement ShutdownOnSucess because there is a method cancel() (the equivalent of shutdown())).</div><div data-marker="__QUOTED_TEXT__">Errgroup does not have to cover all scenarios because in Go you can always fallback on using channels. Errgroup is a nice structured concurrency API for some special cases while channels is the more general API.<br></div><div data-marker="__QUOTED_TEXT__"><br data-mce-bogus="1"></div><div data-marker="__QUOTED_TEXT__">In term of typing, Errgroup is not better than STS.ShutdownOnFailure because both erase the type of the error/exception. Note that errgroup what developed before go had generics. <br data-mce-bogus="1"></div><div data-marker="__QUOTED_TEXT__"><br data-mce-bogus="1"></div><div data-marker="__QUOTED_TEXT__">I believe STS should not focus only on the special cases STS.ShutdownOnFailure and STS.ShutdownOnSucess, but also provides a thread safe way to implement most of the general cases.</div><div data-marker="__QUOTED_TEXT__">What i am proposing cover all scenarios that could be implemented by a channel with multiple writers but only one reader. For those cases, I believe that the a join(Function<Stream,T>) is a better API than the channel API because it is a structured concurrency API and it's also better than letting users to write a poor man implementation of channels as a subclass of STS.</div><div data-marker="__QUOTED_TEXT__"><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><div>
<br class="">
<blockquote class="">
<div class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">What
 i'm proposing is just a glorified blocking queue + a spliterator but it allows to implement any logic more easily.</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
</div>
</blockquote>
<div><br class="">
</div>
<div>Channels are something we’re interested in, but as an orthogonal feature to — putting it very simply — solve the “blocking queue closing” problem (and perhaps some others, such as distributed implementation, easy functional transformations).</div></div></blockquote><div><br></div><div>yes,</div><div>what i'm saying is not that we need channels, as you said it's an orthogonal feature, what i'm saying is that there is a category of problem that could be solved by a channel with multiple writers and only one reader, for those problem, we can also provide a structured concurrency API.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><div>
<div><br class="">
</div>
<blockquote class="">
<div class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">You're
 aware that I have demonstrated the Java 19 version of STS to numerous conference attendees. However, the requirement to create custom subclasses is often a point of confusion for them. Many existing APIs attempt to separate the concurrency aspect, which is
 managed by the implementation, from the business logic that users should focus on.</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">I
 believe the current incarnation of STS is falling short.</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
</div>
</blockquote>
<div><br class="">
</div>
<div>Can you please try to clearly identify the problem you’re trying to solve? E.g. doing X well with STS is hard</div></div></blockquote><div><br></div><div>Doing anything which is not shutdown on failure/shutdown on success is hard with STS because STS does not help users to write a correct thread safe implementation of a subclass of STS that overrides handleComplete().<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><div><div> </div>
</div>
<br class="">
<div><br class="">
</div>
<div>— Ron</div></blockquote>Rémi<div><br></div></div></div></body></html>