func()

in appinsights/throttle.go [99:144]


func (throttle *throttleManager) waitForReady(throttledUntil time.Time) bool {
	duration := throttledUntil.Sub(currentClock.Now())
	if duration <= 0 {
		return true
	}

	var notify []chan bool

	// --- Throttled and waiting ---
	t := currentClock.NewTimer(duration)

	for {
		select {
		case <-t.C():
			for _, n := range notify {
				n <- true
			}

			return true
		case msg := <-throttle.msgs:
			if msg.query {
				msg.result <- true
			} else if msg.wait {
				notify = append(notify, msg.result)
			} else if msg.stop {
				for _, n := range notify {
					n <- false
				}

				msg.result <- true

				return false
			} else if msg.throttle {
				if msg.timestamp.After(throttledUntil) {
					throttledUntil = msg.timestamp

					if !t.Stop() {
						<-t.C()
					}

					t.Reset(throttledUntil.Sub(currentClock.Now()))
				}
			}
		}
	}
}