Connect and disconnect on the current thread and dispatch events on the connection events handler

Summary:
Addresses an issue with the connect and disconnect sequence.

Both, connect and disconnect should be performed 'synchronously' instead of being queued in the connection event thread.

Events should be queued in the connection event thread instead.

Reviewed By: passy

Differential Revision: D31195525

fbshipit-source-id: c15487ea163dd277dacee0e5669944ac6971355f
This commit is contained in:
Lorenzo Blasa
2021-09-27 09:28:01 -07:00
committed by Facebook GitHub Bot
parent f6af85ee7e
commit 12865fd0bc

View File

@@ -169,7 +169,8 @@ bool FlipperWebSocket::connect(FlipperConnectionManager* manager) {
promise.set_value(false);
}
}
eventHandler(event);
eventBase_->runInEventBaseThread(
[eventHandler, event]() { eventHandler(event); });
};
socket_.messageHandler = ^(const std::string& message) {
this->messageHandler_(message);
@@ -187,7 +188,7 @@ bool FlipperWebSocket::connect(FlipperConnectionManager* manager) {
};
}
eventBase_->runInEventBaseThread([this]() { [socket_ connect]; });
[socket_ connect];
auto state = connected.wait_for(std::chrono::seconds(10));
if (state == std::future_status::ready) {
@@ -199,10 +200,8 @@ bool FlipperWebSocket::connect(FlipperConnectionManager* manager) {
}
void FlipperWebSocket::disconnect() {
eventBase_->runInEventBaseThread([this]() {
[socket_ disconnect];
socket_ = NULL;
});
}
void FlipperWebSocket::send(