[External] : Re: A new build and a new structured concurrency API
Alex Otenko
oleksandr.otenko at gmail.com
Thu Nov 18 16:43:36 UTC 2021
Yes, that's the behaviour that I expect, hence the question. Since shutdown
makes the Futures behave like a cancel was called, why is onComplete
singled out, and doesn't behave like when the Future got cancelled - i.e.
is not guaranteed to be invoked on shutdown, even though guaranteed to be
invoked on Future.cancel
Alex
On Thu, 18 Nov 2021, 11:31 Alan Bateman, <Alan.Bateman at oracle.com> wrote:
> On 18/11/2021 10:02, Alex Otenko wrote:
> > I see why break may be an analogue, but don't see why it is the right
> one.
> >
> > Right now the tasks finish in one of four ways:
> >
> > Success with a value
> > Failure with Exception
> > Someone aborted, a subclass of Failure
> > Shutdown
> >
> > And it is ok to use onComplete for three cases, but not the last? So now
> > really all handling is spread across two sites, predictably requiring
> more
> > code and more complexity in interactions with the other three termination
> > conditions.
> A task completes with a result, an exception, or it is cancelled. This
> will be familiar to everyone that uses Future::get. This project has not
> introduced any new states or ways for a task to complete. When using the
> 2-arg fork method then the onComplete operation is invoked when the task
> completes, irrespective of whether it completed with a result,
> exception, or was cancelled.
>
> The shutdown method is on StructuredExecutor, not Future. The javadoc
> tries to be clear that it is for cases where you've got an interesting
> result and are no longer interested in the results of other tasks. The
> shutdown method closes the front door to prevent new threads from
> starting. It also interrupts the threads that are running the tasks that
> haven't completed yet. It also tries to make it clear that when shutdown
> completes that are tasks are "done" (it links to Future::isDone). You
> shouldn't need to use Future::get with this API but if you were then you
> should see that Future::get wakes up when SE::shutdown is called.
>
> -Alan
>
>
>
>
>
More information about the loom-dev
mailing list