Skip to content

Commit

Permalink
Add msg queuing for all messages for public agents
Browse files Browse the repository at this point in the history
Fixes #944
  • Loading branch information
TheNeikos committed Mar 8, 2020
1 parent 2b90c38 commit 90aa108
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
});
Expand Down Expand Up @@ -689,6 +691,14 @@ impl<AGN: Agent> PublicBridge<AGN> {
}
});
}

fn send_message(&self, msg: ToWorker<AGN::Input>) {
if self.worker_is_loaded() {
send_to_remote::<AGN>(&self.worker, msg);
} else {
self.msg_to_queue(msg.pack());
}
}
}

fn send_to_remote<AGN: Agent>(
Expand All @@ -713,11 +723,7 @@ fn send_to_remote<AGN: Agent>(
impl<AGN: Agent> Bridge<AGN> for PublicBridge<AGN> {
fn send(&mut self, msg: AGN::Input) {
let msg = ToWorker::ProcessInput(self.id, msg);
if self.worker_is_loaded() {
send_to_remote::<AGN>(&self.worker, msg);
} else {
self.msg_to_queue(msg.pack());
}
self.send_message(msg);
}
}

Expand Down

0 comments on commit 90aa108

Please sign in to comment.