Reschedule adds/updates/deletes an event in the heap, whichever operation is applicable (use a zero time to delete).
(eh eventHandler, t time.Time)
| 413 | // Reschedule adds/updates/deletes an event in the heap, whichever |
| 414 | // operation is applicable (use a zero time to delete). |
| 415 | func (em *eventManager) Reschedule(eh eventHandler, t time.Time) { |
| 416 | em.mu.Lock() |
| 417 | defer em.mu.Unlock() |
| 418 | defer em.updateTimerLocked() |
| 419 | |
| 420 | e, ok := em.reverseLookup[eh] |
| 421 | if !ok { |
| 422 | if t.IsZero() { |
| 423 | // eh is not scheduled and also not active, so do nothing. |
| 424 | return |
| 425 | } |
| 426 | // eh is not scheduled but is active, so add it. |
| 427 | heap.Push(em, &event{ |
| 428 | when: t, |
| 429 | eh: eh, |
| 430 | }) |
| 431 | em.processEventsLocked(em.now) // This is always safe and required when !t.After(em.now). |
| 432 | return |
| 433 | } |
| 434 | |
| 435 | if t.IsZero() { |
| 436 | // e is scheduled but not active, so remove it. |
| 437 | heap.Remove(em, e.position) |
| 438 | return |
| 439 | } |
| 440 | |
| 441 | // e is scheduled and active, so update it. |
| 442 | e.when = t |
| 443 | heap.Fix(em, e.position) |
| 444 | em.processEventsLocked(em.now) // This is always safe and required when !t.After(em.now). |
| 445 | } |
| 446 | |
| 447 | // AdvanceTo updates the current time to tm and fires all events scheduled |
| 448 | // before or equal to tm. When an event fires, it may request rescheduling and |