You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@mesos.apache.org by "Michael Park (JIRA)" <ji...@apache.org> on 2015/08/01 05:27:04 UTC
[jira] [Commented] (MESOS-3188) Add tuple-awareness to Future
callbacks.
[ https://issues.apache.org/jira/browse/MESOS-3188?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14650129#comment-14650129 ]
Michael Park commented on MESOS-3188:
-------------------------------------
An alternative design would be to introduce an {{unpacked}} adaptor that takes any function {{F}} and returns a new function that takes a tuple and invokes {{F}} by unpacking the elements of the tuple. A sketch of the function:
{code}
template <typename F>
auto unpacked(const F& f) { return [f](auto &&args) { return std::apply(f, std::forward<decltype(args)>(args)); } }
{code}
Since we generally prefer to be explicit in Mesos, this may be a preferred design. Furthermore, I think this is a more generic utility to have compared to embedding implicit unpacking behavior to {{Future}}. If we had another place that we wanted to support the implicit unpacking behavior, we would have to go and update that feature as well. With {{unpacked}}, we would simply pass {{unpacked(F)}} instead.
Sample usage:
{code}
{
// Subprocess example.
await(s.get().status(),
io::read(s.get().out().get()),
io::read(s.get().err().get()))
.then(unpacked(defer(self(), &Self::continue, lambda::_1)));
}
void continue(
Future<Option<int>> status,
Future<string> output,
Future<string> error)
{
...
}
{code}
> Add tuple-awareness to Future callbacks.
> ----------------------------------------
>
> Key: MESOS-3188
> URL: https://issues.apache.org/jira/browse/MESOS-3188
> Project: Mesos
> Issue Type: Improvement
> Components: libprocess
> Reporter: Benjamin Mahler
>
> Future is currently single-valued and so the only way to create a multi-value Future is to use a custom struct or a tuple. Since Future is not currently "tuple-aware", continuations have to take a tuple as well, and manually unpack:
> {code}
> {
> // Subprocess example.
> await(s.get().status(),
> io::read(s.get().out().get()),
> io::read(s.get().err().get()))
> .then(defer(self(), &Self::continue, lambda::_1));
> }
> void continue(std::tuple<
> Future<Option<int>>,
> Future<string>,
> Future<string>> results)
> {
> Future<Option<int>> status = std::get<0>(results);
> Future<string> output = std::get<1>(results);
> Future<string> error = std::get<2>(results);
> }
> {code}
> Since multi-value Future (i.e. Future<T1, T2, ...>) seems to be a bad design choice, being tuple aware can improve the code cleanliness by unpacking the tuple automatically for the continuation:
> {code}
> {
> // Subprocess example.
> await(s.get().status(),
> io::read(s.get().out().get()),
> io::read(s.get().err().get()))
> .then(defer(self(), &Self::continue, lambda::_1));
> }
> void continue(
> Future<Option<int>> status,
> Future<string> output,
> Future<string> error)
> {
> ...
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)