go-tdlib
go-tdlib copied to clipboard
Workaround for Error: Receive is called after Client destroy
Hack of tdlib.go for DestroyInstance()
var IsClosed = false
func NewClient(config Config) *Client {
// ...
go func() {
for !IsClosed {
// get update
updateBytes := client.Receive(10)
// ...
}
}()
// ...
}
usage:
tdlib.IsClosed = true
time.Sleep(1 * time.Second)
client.DestroyInstance()

https://core.telegram.org/tdlib/docs/td__json__client_8h.html
Solution by @levlam
"Receive is called after Client destroy" is always a bug of those, who uses TDLib. You should move call to client.DestroyInstance() to the thread, which calls receive, instead of testing your luck with Sleep.
You can also use new JSON interface (td_create_client_id/td_send/td_receive), which removes possibility to do this bug.
See also https://github.com/tdlib/td/issues/1394