brian-armstrong / gpio

Go library to do GPIO on systems with /sys/class/gpio (sysfs)
BSD 3-Clause "New" or "Revised" License
140 stars 50 forks source link

Non-blocking way to catch the pin change events ? #9

Closed al2389 closed 6 years ago

al2389 commented 6 years ago

watcher.Watch() is good, but it blocks the program execution. Is there a non-blocking way to catch the pin change events ?

Can watcher.Notification do this ? If yes, could you give me some example code ? I am very new to golang. Thanks.

al2389 commented 6 years ago

I can use goroutine, thanks.

brian-armstrong commented 6 years ago

Sounds like you might have figured it out.

If you need to use select on multiple Go channels simultaneously, then watcher.Notification is helpful since you can just receive from it directly. If you want to do 2 blocking things at the same time, you can select result channels from both, and watcher.Notification can be one of those channels.