discordgo icon indicating copy to clipboard operation
discordgo copied to clipboard

feat(wsapi): Gracefully close the websocket connection

Open armsnyder opened this issue 1 year ago • 0 comments

This PR removes a time.Sleep(1 * time.Second) from Session.Close().

Instead, I implemented the websocket close handshake described in this comment: https://github.com/gorilla/websocket/issues/448#issuecomment-469903859

The reason I would like to see this change is that the time.Sleep was causing my unit tests to run slowly.

I tested this change by running this program a few times:

package main

import (
	"github.com/bwmarrin/discordgo"
	"github.com/samber/lo"
)

func main() {
	session := lo.Must(discordgo.New(Getenv("BOT_TOKEN")))
	session.LogLevel = discordgo.LogDebug
	lo.Must0(session.Open())
	lo.Must0(session.Close())
}

armsnyder avatar Mar 12 '23 04:03 armsnyder