Skip to content

Instantly share code, notes, and snippets.

@svinota
Created April 22, 2016 07:18
Show Gist options
  • Save svinota/b1a6f29b4c8a9cf96cf6d6f35afe23e1 to your computer and use it in GitHub Desktop.
Save svinota/b1a6f29b4c8a9cf96cf6d6f35afe23e1 to your computer and use it in GitHub Desktop.
package main
import (
"os"
"time"
"github.com/vishvananda/netlink"
)
func WaitForLink(ch <-chan netlink.LinkUpdate, ifaceName string) bool {
for {
timeout := time.After(time.Minute)
select {
case update := <-ch:
if ifaceName == update.Link.Attrs().Name {
return true
}
case <-timeout:
return false
}
}
}
func main() {
ch := make(chan netlink.LinkUpdate)
done := make(chan struct{})
defer close(done)
if err := netlink.LinkSubscribe(ch, done); err != nil {
os.Exit(2)
}
if !WaitForLink(ch, "dummy2") {
os.Exit(3)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment