Run Loop Synchronization
Closed this issue · 2 comments
Hello.
I'm using rxqt
as an integration tool between rxcpp
and qt
. when using timed operators of rxcpp
like debounce
, it is necessary to use a run_loop to syncronize the rxcpp run loop with qt run loop:
Provide an interface between the Qt event loop and RxCpp's run loop scheduler. This enables use of timed RxCpp operators (such as delay and debounce) with RxQt.
but i was unable to use debounce
in this example:
#include <QCoreApplication>
#include <QTimer>
#include <iostream>
#include <rxqt/rxqt.hpp>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
rxqt::run_loop rl;
QTimer timer;
rxqt::from_signal(&timer, &QTimer::timeout)
.debounce(std::chrono::milliseconds(1000))
.subscribe([](const auto&) {
std::cout << "Emitting Every 1 sec" << std::endl;
});
timer.start(100);
return a.exec();
}
nothing would be logged to the console. but when rxqt::run_loop rl
is commented out, everything would work as expected.
Is there anything that i'm missing? when should this run_loop be used?
And a great thanks for the library.
Thank you for using rxqt! and sorry for late.
In this case, .debounce(milliseconds(1000))
filters out all events and no output is a correct result.
What you are looking for is perhaps sample_with_time
.
#include <QCoreApplication>
#include <QTimer>
#include <iostream>
#include <rxqt/rxqt.hpp>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
rxqt::run_loop rl;
QTimer timer;
rxqt::from_signal(&timer, &QTimer::timeout)
.sample_with_time(std::chrono::milliseconds(1000))
.subscribe([](const auto&) {
std::cout << "Emitting Every 1 sec" << std::endl;
});
timer.start(100);
return a.exec();
}
Hello, Thanks for responding !
You are absolutely right, sorry for posting pure rx
question in this repository, I was a little confused on run_loop
usage.