diff --git a/src/agent.rs b/src/agent.rs index d87e7afb989..77583287e4d 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -645,7 +645,9 @@ impl Discoverer for Public { }), }; let launched = RemoteAgent::new(worker, slab); - entry.insert(launched).create_bridge(callback) + let bridge = entry.insert(launched).create_bridge(callback); + bridge.send_message(ToWorker::Connected(bridge.id)); + bridge } } }); @@ -689,6 +691,14 @@ impl PublicBridge { } }); } + + fn send_message(&self, msg: ToWorker) { + if self.worker_is_loaded() { + send_to_remote::(&self.worker, msg); + } else { + self.msg_to_queue(msg.pack()); + } + } } fn send_to_remote( @@ -713,11 +723,7 @@ fn send_to_remote( impl Bridge for PublicBridge { fn send(&mut self, msg: AGN::Input) { let msg = ToWorker::ProcessInput(self.id, msg); - if self.worker_is_loaded() { - send_to_remote::(&self.worker, msg); - } else { - self.msg_to_queue(msg.pack()); - } + self.send_message(msg); } }