From 5073fce2f76655a846ee862beffa2a47f014e034 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Wed, 27 Feb 2019 14:42:41 -0800 Subject: [PATCH] Implement LiveSession::restart_with_new_project as foundation for reloading --- server/src/live_session.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/server/src/live_session.rs b/server/src/live_session.rs index 668353e1..957a2d37 100644 --- a/server/src/live_session.rs +++ b/server/src/live_session.rs @@ -1,4 +1,5 @@ use std::{ + mem, sync::{Arc, Mutex}, }; @@ -63,8 +64,8 @@ impl LiveSession { let session_id = SessionId::new(); Ok(LiveSession { - project, session_id, + project, message_queue, rbx_session, imfs, @@ -72,7 +73,14 @@ impl LiveSession { }) } - pub fn get_project(&self) -> &Project { - &self.project + /// Restarts the live session using the given project while preserving the + /// internal session ID. + pub fn restart_with_new_project(&mut self, project: Arc) -> Result<(), LiveSessionError> { + let mut new_session = LiveSession::new(project)?; + new_session.session_id = self.session_id; + + mem::replace(self, new_session); + + Ok(()) } } \ No newline at end of file