aboutsummaryrefslogtreecommitdiff
path: root/src/client/bridge
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-12-09 19:51:43 -0800
committerZeyla Hellyer <[email protected]>2017-12-09 19:51:43 -0800
commit65233ad6f3d002f72942aaf811514fa9d29ad068 (patch)
tree75a4ffb6250f11a2dc5c5f03d0397b852f066cc5 /src/client/bridge
parentFix syntax highlighting in README (diff)
downloadserenity-65233ad6f3d002f72942aaf811514fa9d29ad068.tar.xz
serenity-65233ad6f3d002f72942aaf811514fa9d29ad068.zip
Shutdown everything on ShardManager::shutdown_all
Calling `ShardManager::shutdown_all` will now send a message to the shard queuer and shard monitor to shutdown. This will now cause `Client::start_connection` to exit. Additionally, `Client::start_connection` and related functions that call this (e.g. `Client::start_autosharded`) now return `Ok(())` on clean exits.
Diffstat (limited to 'src/client/bridge')
-rw-r--r--src/client/bridge/gateway/mod.rs4
-rw-r--r--src/client/bridge/gateway/shard_manager.rs6
-rw-r--r--src/client/bridge/gateway/shard_manager_monitor.rs1
-rw-r--r--src/client/bridge/gateway/shard_runner.rs5
4 files changed, 16 insertions, 0 deletions
diff --git a/src/client/bridge/gateway/mod.rs b/src/client/bridge/gateway/mod.rs
index 752b015..c5410e6 100644
--- a/src/client/bridge/gateway/mod.rs
+++ b/src/client/bridge/gateway/mod.rs
@@ -99,6 +99,10 @@ pub enum ShardManagerMessage {
/// [`ShardManager`]: struct.ShardManager.html
/// [`ShardManagerMonitor`]: struct.ShardManagerMonitor.html
ShutdownAll,
+ /// Indicator that a [`ShardManager`] has initiated a shutdown, and for the
+ /// component that receives this to also shutdown with no further action
+ /// taken.
+ ShutdownInitiated,
}
/// A message to be sent to the [`ShardQueuer`].
diff --git a/src/client/bridge/gateway/shard_manager.rs b/src/client/bridge/gateway/shard_manager.rs
index 9e23d92..fbfd2f6 100644
--- a/src/client/bridge/gateway/shard_manager.rs
+++ b/src/client/bridge/gateway/shard_manager.rs
@@ -92,6 +92,7 @@ use framework::Framework;
/// [`Client`]: ../../struct.Client.html
#[derive(Debug)]
pub struct ShardManager {
+ monitor_tx: Sender<ShardManagerMessage>,
/// The shard runners currently managed.
///
/// **Note**: It is highly unrecommended to mutate this yourself unless you
@@ -146,6 +147,7 @@ impl ShardManager {
});
let manager = Arc::new(Mutex::new(Self {
+ monitor_tx: thread_tx,
shard_queuer: shard_queue_tx,
runners,
shard_index,
@@ -194,6 +196,7 @@ impl ShardManager {
});
let manager = Arc::new(Mutex::new(Self {
+ monitor_tx: thread_tx,
shard_queuer: shard_queue_tx,
runners,
shard_index,
@@ -352,6 +355,9 @@ impl ShardManager {
for shard_id in keys {
self.shutdown(shard_id);
}
+
+ let _ = self.shard_queuer.send(ShardQueuerMessage::Shutdown);
+ let _ = self.monitor_tx.send(ShardManagerMessage::ShutdownInitiated);
}
fn boot(&mut self, shard_info: [ShardId; 2]) {
diff --git a/src/client/bridge/gateway/shard_manager_monitor.rs b/src/client/bridge/gateway/shard_manager_monitor.rs
index 4a64473..d98827d 100644
--- a/src/client/bridge/gateway/shard_manager_monitor.rs
+++ b/src/client/bridge/gateway/shard_manager_monitor.rs
@@ -48,6 +48,7 @@ impl ShardManagerMonitor {
break;
},
+ ShardManagerMessage::ShutdownInitiated => break,
}
}
}
diff --git a/src/client/bridge/gateway/shard_runner.rs b/src/client/bridge/gateway/shard_runner.rs
index 15712f3..6ca73eb 100644
--- a/src/client/bridge/gateway/shard_runner.rs
+++ b/src/client/bridge/gateway/shard_runner.rs
@@ -240,6 +240,11 @@ impl<H: EventHandler + Send + Sync + 'static> ShardRunner<H> {
true
},
+ ShardManagerMessage::ShutdownInitiated => {
+ // nb: not sent here
+
+ true
+ },
}
ShardClientMessage::Runner(x) => match x {
ShardRunnerMessage::ChunkGuilds { guild_ids, limit, query } => {