How to compose requests?

11 views
Skip to first unread message

Ivan Baidakou

unread,
Oct 13, 2019, 3:29:40 PM10/13/19
to actor-framework
Hi!

How can I compose responses? I'd like to have something like:

void method(event_based_actor *self, actor other_actor) {
  auto f1 = self->request(other_actor, 1s, my_atom::value);
  auto f2 = self->request(other_actor, 1s, my_atom::value);
  int counter = 0;
  compose(f1, f2).then([=](response_atom ok) mutable {
      if (++counter == 2) {
        // my action
      }
  },[=](error err){
      // my error action
  });
}


Thanks,
Ivan Baidakou

Dominik Charousset

unread,
Oct 15, 2019, 7:11:49 AM10/15/19
to actor-f...@googlegroups.com
Hi,

currently there is no convenience API for composing multiple request results. You have to it manually at the moment:

```
auto counter = std::make_shared<int>(0);
self->request(...).then([](...) {
  if (++*counter == 2) {
    // ...
  }
});
self->request(...).then([](...) {
  if (++*counter == 2) {
    // ...
  }
});
```

However, I think composing response promises is a common-enough use case to support it with first class primitives. I've created an issue for that [1].

--
You received this message because you are subscribed to the Google Groups "actor-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to actor-framewo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/actor-framework/ea8b248d-69b8-4744-8142-023cc60941ee%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages