Skip to content

Subscriber's message handler wasn't called after leaving the try block #125

Answered by milyin
Alan-Kuan asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @Alan-Kuan !

After leaving the try {} block both the session and subsriber are automatically destroyed as they left the lexical scope. You may use std::unique_ptr or just declare unitialized session and subscriber outside the block, using null constructors:

void runAsSubscriber(const char* conf_path) {
    zenoh::Session session(std::nullptr);
    zenoh::Subscriber subscriber(std::nullptr);
    try {
        auto config = zenoh::expect<zenoh::Config>(zenoh::config_from_file(conf_path));
        session = zenoh::expect<zenoh::Session>(zenoh::open(std::move(config)));
        subscriber = zenoh::expect<zenoh::Subscriber>(session.declare_subscriber(
            "my/topic", messageHandler
…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Alan-Kuan
Comment options

Answer selected by Alan-Kuan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants