If you fix those two, then you'll still have a problem of missing the first timer, and the output will be this:
t 0
t 0.1
t 0.2
t 0.3
t 0.4
t 0.5
onset1 0.5
t 0.6
t 0.7
The problem here is that onset0 actually fires here (see below). This is before the listener is registered, so it gets missed.
stream<double> onset0 = onsetEvent(ts, 0);
stream<double> onset1 = onsetEvent(ts, 0.5); <--- HERE
auto kill0 = onset0.listen([](double t) {
std::cout << "onset0 " << t << std::endl;
});
auto kill1 = onset1.listen([](double t) {
std::cout << "onset1 " << t << std::endl;
});
This can be fixed by doing all the initialization in a single transaction (this is generally a good idea anyway). Note that anything that happens inside a transaction is considered by Sodium to be happening at the same time, so the order of statements makes no difference, apart from obvious data dependencies.
--- main.cpp.orig 2016-11-25 05:39:08.142536547 +1300
+++ main.cpp 2016-11-25 05:40:43.812154423 +1300
@@ -86,6 +86,7 @@
std::shared_ptr<test_impl> impl(new test_impl);
sodium::timer_system<double> ts(impl);
+ transaction trans;
stream<double> onset0 = onsetEvent(ts, 0);
stream<double> onset1 = onsetEvent(ts, 0.5);
@@ -96,6 +97,7 @@
auto kill1 = onset1.listen([](double t) {
std::cout << "onset1 " << t << std::endl;
});
+ trans.close();
for (double t = 0; t <= 10; t += 0.1) {
std::cout << "t " << t << std::endl;
Now you'll get the output you expect:
t 0
onset0 0
t 0.1
t 0.2
t 0.3
t 0.4
t 0.5
onset1 0.5
t 0.6
t 0.7