Example #1
0
 void receive(Net& net, Peer* from, int m)
 {
     set.insert(m);
     ++m;
     if (m < 5)
     {
         for(auto const& link : net.links(this))
             net.send(this, link.to,
                 [&, mm = m, to = link.to]
                 {
                     to->receive(net, this, mm);
                 });
     }
 }
Example #2
0
 void start(Net& net)
 {
     using namespace std::chrono_literals;
     auto t = net.timer(1s,
         [&]{ set.insert(0); });
     if (id == 0)
     {
         for(auto const& link : net.links(this))
             net.send(this, link.to,
                 [&, to = link.to]
                 {
                     to->receive(net, this, 1);
                 });
     }
     else
     {
         net.cancel(t);
     }
 }