Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Hub {
- rooms: Vec<String>,
- }
- impl Actor for Hub {
- type Context = Context<Self>;
- }
- impl Hub {
- pub fn new() -> Hub {
- Hub {
- rooms: vec![]
- }
- }
- fn get_unique_id(&self) -> String {
- String::from("unique_id")
- }
- }
- struct CreateRoom;
- impl Message for CreateRoom {
- type Result = String;
- }
- impl Handler<CreateRoom> for Hub {
- type Result = String;
- fn handle(&mut self, msg: CreateRoom, ctx: &mut Context<Self>) -> Self::Result {
- let id = self.get_unique_id();
- self.rooms.push(id.clone());
- id
- }
- }
- //External wrapper
- struct HubWrapper(Addr<Hub>);
- impl HubWrapper {
- pub fn add(&self) -> String {
- let res = self.0.send(CreateRoom);
- //how can I exec the future and return here the ID of this new room?
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement