Example #1
0
func sendInvites(ctx *context.T, disc discovery.T, notify chan<- string) {
	ctx.Infof("Scanning for peers to invite")
	ctx, cancel := context.WithCancel(ctx)
	defer cancel()
	updates, err := disc.Scan(ctx, fmt.Sprintf("v.InterfaceName=%q", interfaceName))
	if err != nil {
		ctx.Panic(err)
	}
	for u := range updates {
		if u.IsLost() {
			continue
		}
		ctx.Infof("Sending invitations to %+v", u.Addresses())
		if addr := sendOneInvite(ctx, u.Addresses()); len(addr) > 0 {
			notify <- addr
			go func() {
				for range updates {
				}
			}()
			return
		}
	}
	ctx.Infof("Stopped scanning for peers to invite without finding one")
}