diff options
| author | acdenisSK <[email protected]> | 2017-07-16 01:45:09 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-07-16 01:51:52 +0200 |
| commit | 9900b20bf5cd4036cd8d8ba28bdcd852f2c89d2f (patch) | |
| tree | 7d87b56779b2df391938d8e3517d73b1a4b3f217 /src/client | |
| parent | Actually, revert the publicity and add `#[derive(Clone)]` (diff) | |
| download | serenity-9900b20bf5cd4036cd8d8ba28bdcd852f2c89d2f.tar.xz serenity-9900b20bf5cd4036cd8d8ba28bdcd852f2c89d2f.zip | |
Add a close handle for closing the shards in another thread
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/mod.rs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/client/mod.rs b/src/client/mod.rs index 3024eea..428d773 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -56,6 +56,15 @@ use ::framework::Framework; static HANDLE_STILL: AtomicBool = ATOMIC_BOOL_INIT; +#[derive(Clone)] +pub struct CloseHandle; + +impl CloseHandle { + pub fn close(self) { + HANDLE_STILL.store(false, Ordering::Relaxed); + } +} + /// The Client is the way to be able to start sending authenticated requests /// over the REST API, as well as initializing a WebSocket connection through /// [`Shard`]s. Refer to the [documentation on using sharding][sharding docs] @@ -595,9 +604,9 @@ impl<H: EventHandler + 'static> Client<H> { self.start_connection([range[0], range[1], total_shards], http::get_gateway()?.url) } - /// Closes all of the shards that are running. - pub fn close(&self) { - HANDLE_STILL.store(false, Ordering::Relaxed); + /// Returns a thread-safe handle for closing shards. + pub fn close_handle(&self) -> CloseHandle { + CloseHandle } // Shard data layout is: @@ -696,7 +705,7 @@ impl<H: EventHandler + 'static> Client<H> { impl<H: EventHandler + 'static> Drop for Client<H> { fn drop(&mut self) { - self.close(); + self.close_handle().close(); } } |