#undef NDEBUG #include #include #include #include #include #include Ev::Io io_main() { auto bus = std::make_shared(); auto flag = std::make_shared(); auto flag2 = std::make_shared(); return Ev::yield().then([=]() { /* Should be benign. */ return bus->raise(42); }).then([=]() { *flag = false; bus->subscribe([=](int const& i) { if (i == 42) *flag = true; return Ev::lift(); }); return bus->raise(40).then([=]() { /* Previous subscription should not have * an effect. */ assert(!*flag); return bus->raise(42); }).then([=] () { /* Subscription should have triggered. */ assert(*flag); return Ev::yield(); }); }).then([=]() { /* Types are strict. */ *flag = false; return bus->raise(42.0).then([=]() { /* Previous subscription should not trigger, * it is registered for int, not double. */ assert(!*flag); return Ev::lift(); }); }).then([=]() { *flag = false; bus->subscribe([=](double const& i) { if (i == 42.0) *flag = true; return Ev::lift(); }); return bus->raise(42.0).then([=]() { assert(*flag); return Ev::lift(); }); }).then([=]() { *flag = false; *flag2 = false; /* Test multiple subscriptions. */ bus->subscribe([=](double const& i) { *flag2 = true; return Ev::lift(); }); return bus->raise(42.0).then([=]() { /* Both subscriptions should have triggered. */ assert(*flag); assert(*flag2); return Ev::lift(); }); }).then([bus] () { /* This function just keeps the bus alive. */ return Ev::lift(); }); } int main() { return Ev::start(io_main().then([](){ return Ev::lift(0); })); }