keyboard
keyboard copied to clipboard
Fix data race in keyboard.Listen() and unit tests, enable race detection
Motivation
There's currently a data race as described here. This makes it hard to enable data race detection for projects using this package. I'm implementing a possible solution using the atomic.Bool wrapper and enabling race detection via -race for go tests. I also had to wrap appending to the slice in a unit test with a lock to fix another data race issue. One caveat of this solution is that using atomic.Bool requires a minimum go version of 1.19.
If bumping to go 1.19 is not desired, I could also change it to wrap access to the shared variable with sync.Mutex