Added eventsMutex and wrap all events calls with it.

Due to some "golangish" code this library have possibility to
run into data race when application is working with callbacks.
This commit adds eventsMutex (which is a sync.Mutex), removed
all "golangish" ifs-map reads, and wrap events map read with
sync.Mutex to avoid data races.
This commit is contained in:
Stanislav N. aka pztrn
2017-10-03 02:03:43 +05:00
parent 1b0acb5f2f
commit e39cceace6
2 changed files with 30 additions and 7 deletions

View File

@@ -39,6 +39,7 @@ type Connection struct {
user string
registered bool
events map[string]map[int]func(*Event)
eventsMutex sync.Mutex
QuitMessage string
lastMessage time.Time