It's worth noting that Go's errgroup
<https://godoc.org/golang.org/x/sync/errgroup> package, which fulfills a
similar need, will block until all tasks have completed, then return the
first error.  The trick is that once the first error is found, the rest of
the remaining tasks ought to be cancelled.  Failure to block on all tasks
can lead to server overload conditions.

On Thu, Jun 22, 2017 at 9:58 AM <[email protected]> wrote:

> Hi Kenton,
>
> Sorry to bring this up from a long time ago, but if it's possible I think
> the behavior of joinPromises should be well-defined. For my use case, which
> I share below, it's preferable for all promises to complete before an
> exception is propagated, but I understand the reasons to go the other way.
>
> Here's my use case:
> For each successful promise in the array I would like to call an "undo"
> promise in case one of the others fail. So I can write code similar to this:
> kj::Vector<kj::Promise<void>> vec;
> std::shared_ptr<Cleanup> cleanup; // This is like an "async guard" to
> undo successful promises in case one fails
> for (p in promises) {
>   vec.add(p.then()[cleanup] { cleanup->add(undo(p)); });
> }
> kj::joinPromises(vec.releaseAsArray()).catch_([cleanup](){
>     cleanup->Go(); // Calls all added undo promises
>  });
>
>
> If an exception is called after all promises complete (successfully or
> unsuccessfully) - I believe this code is correct.
> However, if a single failure propagates immediately - this code is
> incorrect, as one promise can be halfway to successful completion and the
> cleanup won't be called for it when it completes.
>
> Thanks,
> Amit
>
>
> On Saturday, November 14, 2015 at 1:00:08 AM UTC+2, Kenton Varda wrote:
>
>> Yes, an exception from any one promise becomes an exception from the
>> combined promise.
>>
>> I think joinPromises() still waits for all to complete before propagating
>> the exception. Arguably it should cancel all the other promises as soon as
>> one resolves to an exception.
>>
>> -Kenton
>>
> On Fri, Nov 13, 2015 at 2:26 PM, Nathan Hourt <[email protected]> wrote:
>>
> If I use kj::joinPromises to convert my Array<Promise<T>> to
>>> Promise<Array<T>>, and one of the promises breaks, what happens to the
>>> joined promise? Does it break and thereby throw away all of the resolved
>>> promises?
>>>
>>> Thanks!
>>>
>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Cap'n Proto" group.
>>>
>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to [email protected].
>>
>>
>>> Visit this group at http://groups.google.com/group/capnproto.
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Cap'n Proto" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> Visit this group at https://groups.google.com/group/capnproto.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/capnproto.

Reply via email to