aboutsummaryrefslogtreecommitdiff
path: root/examples/02_transparent_guild_sharding/src
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-29 23:33:59 -0800
committerAustin Hellyer <[email protected]>2016-11-29 23:33:59 -0800
commitefad058f596c9df717774cb2e9dafc0035a8df9c (patch)
treeef54b7d65841fb63609a2b5135727922f2d8f81a /examples/02_transparent_guild_sharding/src
parentClean up the codebase (diff)
downloadserenity-efad058f596c9df717774cb2e9dafc0035a8df9c.tar.xz
serenity-efad058f596c9df717774cb2e9dafc0035a8df9c.zip
Add documentation for examples
The examples include a README located in `examples/README.md`, which contains instructions for running these examples. They act as a simple form of tutorial to the library, without getting into too many details.
Diffstat (limited to 'examples/02_transparent_guild_sharding/src')
-rw-r--r--examples/02_transparent_guild_sharding/src/main.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/examples/02_transparent_guild_sharding/src/main.rs b/examples/02_transparent_guild_sharding/src/main.rs
index 19b61d0..1e3446f 100644
--- a/examples/02_transparent_guild_sharding/src/main.rs
+++ b/examples/02_transparent_guild_sharding/src/main.rs
@@ -29,6 +29,9 @@ fn main() {
client.on_message(|context, message| {
if message.content == "!ping" {
+ // The current shard needs to be unlocked so it can be read from, as
+ // multiple threads may otherwise attempt to read from or mutate it
+ // concurrently.
{
let shard = context.shard.lock().unwrap();
@@ -37,7 +40,9 @@ fn main() {
}
}
- let _ = context.say("Pong!");
+ if let Err(why) = context.say("Pong!") {
+ println!("Error sending message: {:?}", why);
+ }
}
});
@@ -51,5 +56,7 @@ fn main() {
//
// This means if you have 5 shards, your total shard count will be 5, while
// each shard will be assigned numbers 0 through 4.
- let _ = client.start_shards(2);
+ if let Err(why) = client.start_shards(2) {
+ println!("Client error: {:?}", why);
+ }
}