You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I perform subscribe(...)->wait(), my understanding is that it's guaranteed that the callbacks for the iaction_listener will have completed before the wait() completes, is that correct?
When I perform connect(...)->wait(), it seems that neither the iaction_listener::on_success nor the callback::connected will necessarily have been called before the wait has completed, is that correct?
Can someone explain why? I can't seem to find any docs on the expected behaviour here.
The text was updated successfully, but these errors were encountered:
async_client client;
token_ptr subToken;
Callback callback;
void Callback::connected(const std::string& cause) {
subToken = client->subscribe('a_topic');
}
initialise() {
client->set_callback(callback);
token_ptr connTok = client->connect(callback);
connTok->wait();
// callback::connected may not have been called yet, and therefore subToken is still null
subToken->wait();
}
Ok, digging in to the C library I think I understand what's going on now. on_success for the connToken is called before the callback::connected, see MqttAsync.c:
line 2236 (*(m->connect.onSuccess))(m->connect.context, &data);
...
line 2258 (*(m->connected))(m->connected_context, reason);
Token::on_success calls cond_.notify_all(); which unblocks/completes the token->wait. This is why my connected callback has not yet been called and subToken remains null.
I wonder whether the async_subscribe.cpp sample should make this clearer? Also the documentation for the Callback::connected should make clear that it will occur after Token::on_success. Documentation in this area is quite sparse in general.
When I perform subscribe(...)->wait(), my understanding is that it's guaranteed that the callbacks for the iaction_listener will have completed before the wait() completes, is that correct?
When I perform connect(...)->wait(), it seems that neither the iaction_listener::on_success nor the callback::connected will necessarily have been called before the wait has completed, is that correct?
Can someone explain why? I can't seem to find any docs on the expected behaviour here.
The text was updated successfully, but these errors were encountered: