proxygen
composition_4.cpp File Reference
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#include <folly/experimental/pushmi/examples/pool.h>
#include <folly/experimental/pushmi/strand.h>
#include <folly/experimental/pushmi/o/request_via.h>
#include <folly/experimental/pushmi/o/tap.h>
#include <folly/experimental/pushmi/o/transform.h>

Go to the source code of this file.

Functions

template<class Io >
auto io_operation (Io io)
 
int main ()
 

Function Documentation

template<class Io >
auto io_operation ( Io  io)

Definition at line 33 of file composition_4.cpp.

References folly::pushmi::operators::request_via, folly::pushmi::operators::tap, and folly::pushmi::operators::transform.

Referenced by main().

33  {
34  return io | op::transform([](auto) { return 42; }) |
35  op::tap([](int v) { printf("io pool producing, %d\n", v); }) |
37 }
PUSHMI_INLINE_VAR constexpr detail::tap_fn tap
Definition: tap.h:126
PUSHMI_INLINE_VAR constexpr detail::request_via_fn request_via
Definition: request_via.h:61
PUSHMI_INLINE_VAR constexpr detail::transform_fn transform
Definition: transform.h:158
int main ( void  )

Definition at line 39 of file composition_4.cpp.

References io_operation(), max, folly::pushmi::strands(), submit, folly::pushmi::operators::tap, and folly::pushmi::via_cast().

39  {
40  mi::pool cpuPool{std::max(1u, std::thread::hardware_concurrency())};
41  mi::pool ioPool{std::max(1u, std::thread::hardware_concurrency())};
42 
43  auto io = ioPool.executor();
44  auto cpu = cpuPool.executor();
45 
46  io_operation(io).via(mi::strands(cpu)) |
47  op::tap([](int v) { printf("cpu pool processing, %d\n", v); }) |
48  op::submit();
49 
50  // when the caller is not going to process the result (only side-effect
51  // matters) or the caller is just going to push the result into a queue.
52  // provide a way to skip the transition to a different executor and make it
53  // stand out so that it has to be justified in code reviews.
55 
56  ioPool.wait();
57  cpuPool.wait();
58 
59  std::cout << "OK" << std::endl;
60 }
auto io_operation(Io io)
requires Invocable< ExecutorFactory & > &&Executor< invoke_result_t< ExecutorFactory & > > &&ConcurrentSequence< invoke_result_t< ExecutorFactory & > > auto strands(ExecutorFactory ef)
Definition: strand.h:246
LogLevel max
Definition: LogLevel.cpp:31
PUSHMI_INLINE_VAR constexpr detail::tap_fn tap
Definition: tap.h:126
requires Same< To, is_sender<> > &&Sender< In > auto via_cast(In in)
Definition: request_via.h:67