RegisterForever is equivalent to Register(), but it tries to re-register if there is a disconnection. The returned error is for the first register attempt. It returns nil if ReadNotify() is ready and it's registered successful.
(kiteURL *url.URL)
| 304 | // attempt. It returns nil if ReadNotify() is ready and it's registered |
| 305 | // successful. |
| 306 | func (k *Kite) RegisterForever(kiteURL *url.URL) error { |
| 307 | errs := make(chan error, 1) |
| 308 | go func() { |
| 309 | for u := range k.kontrol.registerChan { |
| 310 | _, err := k.Register(u) |
| 311 | if err == nil { |
| 312 | k.kontrol.Lock() |
| 313 | k.kontrol.lastRegisteredURL = u |
| 314 | k.kontrol.Unlock() |
| 315 | k.signalReady() |
| 316 | continue |
| 317 | } |
| 318 | |
| 319 | select { |
| 320 | case errs <- err: |
| 321 | default: |
| 322 | } |
| 323 | |
| 324 | k.Log.Error("Cannot register to Kontrol: %s Will retry after %d seconds", |
| 325 | err, kontrolRetryDuration/time.Second) |
| 326 | |
| 327 | time.AfterFunc(kontrolRetryDuration, func() { |
| 328 | select { |
| 329 | case k.kontrol.registerChan <- u: |
| 330 | default: |
| 331 | } |
| 332 | }) |
| 333 | } |
| 334 | }() |
| 335 | |
| 336 | // don't block if there the given url is nil |
| 337 | if kiteURL == nil { |
| 338 | return nil |
| 339 | } |
| 340 | |
| 341 | // initiate a registiration if a url is given |
| 342 | k.kontrol.registerChan <- kiteURL |
| 343 | |
| 344 | select { |
| 345 | case <-k.KontrolReadyNotify(): |
| 346 | return nil |
| 347 | case err := <-errs: |
| 348 | return err |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | // Register registers current Kite to Kontrol. After registration other Kites |
| 353 | // can find it via GetKites() or WatchKites() method. This method does not |