Topic: N3558-A Standardized Representation of Asynchronous


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sun, 28 Apr 2013 18:51:47 +0200
Raw View
Hi,

during a discussion on Boost about a expected class, we have identified=20
a then() function that behaves a little bit different from the one=20
proposed in N3558.
I would like to see if the variation we have identified for the expected=20
class would be as well good for futures.

In order to simplify the user code the continuation function has a=20
value_type as parameter instead of a future reference and is called only=20
if the future is valid. Instead of

future<int> f1 =3D async([]() {return 123;});
future<string> f2 =3D f1.then([](future<int> f) {
return f.get().to_string();
// here .get() won=92t block
});

we can write

future<string> f2 =3D f1.then([](int const & i) {
return i.to_string();
});

BTW, I don't reach to identify in the proposal what is the state of=20
future obtained with then() if the continuation throws. I would expect=20
the exception to be stored on in this future. Is this correct?

The result of the continuation function could be another value type or a=20
future. Returning a future from the continuation could improve the=20
performances in cases where the function is directly the originator of=20
the exception.

future<int> f2 =3D f1.then([](string const & s) -> future<string> {
int i;
if (parse_int(s, i)) return make_ready_future(i);
else make_exceptional_future<int>("Parse error");
});


When the future is not valid the result of the then() call is a future=20
with the exception, so that the first exception is transported during=20
the whole chain.

auto r =3D f().then(g).then(h);

If f() returns a future set with an exception, g and h would not be=20
called at all and r would contain the original exception. If the user=20
access to r.get() the exception will be thrown.

To complete the chain we could add a continuation with an on_exception=20
function that calls its continuation only if the future has an exception.

f().then(g).then(h).on_exception(eh);

What do you think of this variation?

Best,
Vicente

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/?hl=3Den.



.