File: aout.cpp

package info (click to toggle)
actor-framework 0.18.7-1~exp1
  • links: PTS
  • area: main
  • in suites: experimental
  • size: 8,740 kB
  • sloc: cpp: 85,162; sh: 491; python: 187; makefile: 11
file content (33 lines) | stat: -rw-r--r-- 878 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <chrono>
#include <cstdlib>
#include <iostream>
#include <random>

#include "caf/actor_ostream.hpp"
#include "caf/actor_system.hpp"
#include "caf/caf_main.hpp"
#include "caf/event_based_actor.hpp"

using namespace caf;

behavior printer(event_based_actor* self, int32_t num, int32_t delay) {
  aout(self) << "Hi there! This is actor nr. " << num << "!" << std::endl;
  std::chrono::milliseconds timeout{delay};
  self->delayed_send(self, timeout, timeout_atom_v);
  return {
    [=](timeout_atom) {
      aout(self) << "Actor nr. " << num << " says goodbye after waiting for "
                 << delay << "ms!" << std::endl;
    },
  };
}

void caf_main(actor_system& sys) {
  std::random_device rd;
  std::minstd_rand re(rd());
  std::uniform_int_distribution<int32_t> dis{1, 99};
  for (int32_t i = 1; i <= 50; ++i)
    sys.spawn(printer, i, dis(re));
}

CAF_MAIN()