kylelemons/gousb — pull request #9 by nkovacs (2014-06-08 18:06:17+00:00)
Title: Hotplug

You can use it like this:

```go
func Hotplugged(desc *usb.Descriptor, event usb.HotplugEvent) bool {
return false
}

handle, err := ctx.RegisterHotplugCallback(usb.HOTPLUG_ANY, usb.HOTPLUG_ANY, usb.HOTPLUG_ANY,
Hotplugged,
usb.HOTPLUG_EVENT_DEVICE_ARRIVED | usb.HOTPLUG_EVENT_DEVICE_LEFT,
true,
)
```

Returning true in the callback will deregister it.

I also added a HandleEvents method to Context, because if your main loop is an infinite loop, the scheduler will never schedule to goroutine inside usb.go. Alternatively, you can use runtime.Gosched to give it a chance to run.