-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f399044
commit 708f1f9
Showing
5 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
add_subdirectory(interactive_window) | ||
add_subdirectory(doxygen) | ||
add_subdirectory(multi_threaded) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
SET(TARGET multi_threaded) | ||
add_executable(${TARGET} | ||
${TARGET}.cpp | ||
) | ||
|
||
target_link_libraries(${TARGET} PRIVATE rppqt ${RPP_QT_TARGET}::Widgets) | ||
set_target_properties(${TARGET} PROPERTIES FOLDER Examples/rppqt) | ||
|
||
rpp_add_qt_support_to_executable(${TARGET}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include <rpp/rpp.hpp> | ||
#include <rppqt/rppqt.hpp> | ||
|
||
#include <iostream> | ||
|
||
#include <QApplication> | ||
#include <QLabel> | ||
#include <QPushButton> | ||
#include <QMainWindow> | ||
#include <QVBoxLayout> | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
QApplication app{argc, argv}; | ||
QVBoxLayout vbox{}; | ||
|
||
QLabel label{}; | ||
QPushButton button{"CLick me"}; | ||
vbox.addWidget(&label); | ||
vbox.addWidget(&button); | ||
QMainWindow window{}; | ||
|
||
window.setCentralWidget(new QWidget); | ||
window.centralWidget()->setLayout(&vbox); | ||
|
||
window.show(); | ||
|
||
rpp::source::interval(std::chrono::seconds{1}) | ||
.tap([](const auto&) | ||
{ | ||
std::cout << "Interval from thread: " << std::this_thread::get_id() << std::endl; | ||
}) | ||
.combine_latest([](size_t index, size_t amount_of_clicks) | ||
{ | ||
return QString("Seconds since start: %1 Clicks since start: %2").arg(index).arg(amount_of_clicks); | ||
}, | ||
rppqt::source::from_signal(button, &QPushButton::pressed).scan(size_t{}, | ||
[](size_t seed, const auto&) | ||
{ | ||
return seed + 1; | ||
}) | ||
.tap([](const auto&) | ||
{ | ||
std::cout << "Click from thread: " << | ||
std::this_thread::get_id() << std::endl; | ||
}) | ||
.start_with(size_t{0})) | ||
.subscribe_on(rpp::schedulers::new_thread{}) | ||
.observe_on(rppqt::schedulers::main_thread_scheduler{}) | ||
.subscribe([&](const QString& text) | ||
{ | ||
std::cout << "Text updated from thread: " << std::this_thread::get_id() << std::endl; | ||
label.setText(text); | ||
}); | ||
|
||
std::cout << "Application thread: " << std::this_thread::get_id() << std::endl; | ||
|
||
// There we have application's thread, "new_thread" where observable subscribed and interval events happened. | ||
// But we need to update GUI's objects in main thread, so, we forces observable to emit items to subscribe in QT's main thread | ||
// Example of output: | ||
/* | ||
Application thread: 19748 <----- main thread | ||
Interval from thread: 30604 <----- interval happens from another thread | ||
Text updated from thread: 19748 <----- but update then transfered to main thread | ||
Click from thread: 19748 <----- click happens from main thread due to QT logic | ||
Text updated from thread: 19748 <----- and update happens in main thread | ||
Interval from thread: 30604 | ||
Text updated from thread: 19748 | ||
*/ | ||
return app.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
708f1f9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BENCHMARK RESULTS (AUTOGENERATED)
ci-ubuntu-clang
Observable construction
Table
Observable lift
Table
Observable subscribe
Table
Observable subscribe #2
Table
Observer construction
Table
OnNext
Table
Subscriber construction
Table
Subscription
Table
buffer
Table
chains creation test
Table
combine_latest
Table
concat
Table
distinct_until_changed
Table
first
Table
foundamental sources
Table
from
Table
immediate scheduler
Table
just
Table
last
Table
map
Table
merge
Table
observe_on
Table
on_error_resume_next
Table
publish_subject callbacks
Table
publish_subject routines
Table
repeat
Table
scan
Table
single-threaded locks
Table
skip
Table
switch_on_next
Table
take
Table
take_last
Table
take_until
Table
timeout
Table
trampoline scheduler
Table
window
Table
with_latest_from
Table
ci-ubuntu-gcc
Observable construction
Table
Observable lift
Table
Observable subscribe
Table
Observable subscribe #2
Table
Observer construction
Table
OnNext
Table
Subscriber construction
Table
Subscription
Table
buffer
Table
chains creation test
Table
combine_latest
Table
concat
Table
distinct_until_changed
Table
first
Table
foundamental sources
Table
from
Table
immediate scheduler
Table
just
Table
last
Table
map
Table
merge
Table
observe_on
Table
on_error_resume_next
Table
publish_subject callbacks
Table
publish_subject routines
Table
repeat
Table
scan
Table
single-threaded locks
Table
skip
Table
switch_on_next
Table
take
Table
take_last
Table
take_until
Table
timeout
Table
trampoline scheduler
Table
window
Table
with_latest_from
Table
ci-windows
Observable construction
Table
Observable lift
Table
Observable subscribe
Table
Observable subscribe #2
Table
Observer construction
Table
OnNext
Table
Subscriber construction
Table
Subscription
Table
buffer
Table
chains creation test
Table
combine_latest
Table
concat
Table
distinct_until_changed
Table
first
Table
foundamental sources
Table
from
Table
immediate scheduler
Table
just
Table
last
Table
map
Table
merge
Table
observe_on
Table
on_error_resume_next
Table
publish_subject callbacks
Table
publish_subject routines
Table
repeat
Table
scan
Table
single-threaded locks
Table
skip
Table
switch_on_next
Table
take
Table
take_last
Table
take_until
Table
timeout
Table
trampoline scheduler
Table
window
Table
with_latest_from
Table