mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
use cancel to not leak memory
This commit is contained in:
parent
df2aad908f
commit
20f9470ce8
3 changed files with 10 additions and 3 deletions
|
@ -13,7 +13,9 @@ func AddChannel(channelName string) {
|
|||
|
||||
client := Connect()
|
||||
|
||||
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
/*
|
||||
Get my collection instance
|
||||
*/
|
||||
|
|
|
@ -19,7 +19,10 @@ func Connect() *mongo.Client {
|
|||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
err = client.Connect(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
|
@ -12,7 +12,9 @@ func InitialJoin(nb *bot.Bot) {
|
|||
client := Connect()
|
||||
|
||||
collection := client.Database("nourybot").Collection("channels")
|
||||
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
defer client.Disconnect(ctx)
|
||||
|
||||
cur, currErr := collection.Find(ctx, bson.D{})
|
||||
|
|
Loading…
Reference in a new issue