Skip to content

RxROS operators should use subscribe_on rather than observe_on #31

@henrik7264

Description

@henrik7264

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions