Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RxROS operators should use subscribe_on rather than observe_on #31

Open
henrik7264 opened this issue Sep 27, 2019 · 0 comments
Open

RxROS operators should use subscribe_on rather than observe_on #31

henrik7264 opened this issue Sep 27, 2019 · 0 comments

Comments

@henrik7264
Copy link
Collaborator

The following operators: publish_to_topic and send_transform should use subscribe_on rather than observe_on:

    template<typename T>
    auto publish_to_topic(const std::string &topic, const uint32_t queue_size = 10) {
        return [=](auto&& source) {
            ros::Publisher publisher(rxros::node::get_handle().advertise<T>(topic, queue_size));
            source.**observe_on**(rxcpp::synchronize_new_thread()).subscribe(
                [=](const T& msg) {publisher.publish(msg);});
            return source;};}

The observe_on will cause the subscriber to execute in a new thread. However, the source will execute in the thread publish_to_topic was called on. If this is the main thread the publish_to_topic will block the main thread. The subscribe_on will ensure that both the source and the subscriber will execute in a new thread and thus not cause the publish_to_topic to block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant