m1guelpf / chatgpt-telegram

Run your own GPTChat Telegram bot, with a single command!
MIT License
3.9k stars 560 forks source link

avoid name break in chatgpt.SendMessage #106

Closed yuldashboev closed 1 year ago

yuldashboev commented 1 year ago

because there is no logic below for loop, we can just return from the function making code clearer.

yuldashboev commented 1 year ago

Consider the code below causing data racing because of unprotected conversations map

```

chgpt := chatgpt.Init()

go func() {
    ch, err := chgpt.SendMessage("test-racing", 123456)
    if err != nil {
        panic(err)
    }

    for range ch {
    }
}()

go func() {
    ch, err := chgpt.SendMessage("test-racing", 123457)
    if err != nil {
        panic(err)
    }

    for range ch {
    }
}()


Fixed this data racing by protecting map with mutex.