diff options
| author | Zeyla Hellyer <[email protected]> | 2017-06-06 16:31:57 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-06-06 16:31:57 -0700 |
| commit | 175d3a3ef585f6fede959183138d507886192a4e (patch) | |
| tree | 110e145a8437891bc6bc18e1fd2ed04f9c20ab69 /src | |
| parent | Separate websocket client initialization (diff) | |
| download | serenity-175d3a3ef585f6fede959183138d507886192a4e.tar.xz serenity-175d3a3ef585f6fede959183138d507886192a4e.zip | |
Make client join shards and return
Instead of running a loop forever, have the client join threads when
they end.
This is currently a poor way of having the client eventually end, but
for now it's a duck-tape solution, as when one shard completely fails to
reboot it's an indicator of a larger issue (invalidated authentication,
intermittent network issues, etc.)
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/mod.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/client/mod.rs b/src/client/mod.rs index ec2af1e..ff5e4bd 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -937,6 +937,8 @@ impl Client { let shards_index = shard_data.map_or(0, |x| x[0]); let shards_total = shard_data.map_or(1, |x| x[1] + 1); + let mut threads = vec![]; + for shard_number in shards_index..shards_total { let shard_info = shard_data.map(|s| [shard_number, s[2]]); @@ -993,9 +995,9 @@ impl Client { } }}; - thread::spawn(move || { + threads.push(thread::spawn(move || { monitor_shard(monitor_info); - }); + })); }, Err(why) => warn!("Error starting shard {:?}: {:?}", shard_info, why), } @@ -1006,9 +1008,11 @@ impl Client { thread::sleep(Duration::from_secs(5)); } - loop { - thread::sleep(Duration::from_secs(1)); + for thread in threads { + let _ = thread.join(); } + + Ok(()) } } |