本文整理汇总了Golang中github.com/couchbase/sync_gateway/base.SequenceClock.AnyAfter方法的典型用法代码示例。如果您正苦于以下问题:Golang SequenceClock.AnyAfter方法的具体用法?Golang SequenceClock.AnyAfter怎么用?Golang SequenceClock.AnyAfter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/couchbase/sync_gateway/base.SequenceClock
的用法示例。
在下文中一共展示了SequenceClock.AnyAfter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: pollForChanges
func (k *kvChannelIndex) pollForChanges(stableClock base.SequenceClock, newChannelClock base.SequenceClock) (hasChanges bool, cancelPolling bool) {
changeCacheExpvars.Add(fmt.Sprintf("pollCount-%s", k.channelName), 1)
// Increment the overall poll count since a changes request (regardless of whether there have been polled changes)
totalPollCount := atomic.AddUint32(&k.pollCount, 1)
unreadPollCount := atomic.LoadUint32(&k.unreadPollCount)
if unreadPollCount > kMaxUnreadPollCount {
// We've sent a notify, but had (kMaxUnreadPollCount) polls without anyone calling getChanges.
// Assume nobody is listening for updates - cancel polling for this channel
return false, true
}
if unreadPollCount > 0 {
// Give listeners more time to call getChanges, but increment
atomic.AddUint32(&k.unreadPollCount, 1)
}
k.lastPolledLock.Lock()
defer k.lastPolledLock.Unlock()
// First poll handling
if k.lastPolledChannelClock == nil {
k.lastPolledChannelClock = k.clock.Copy()
k.lastPolledSince = k.clock.Copy()
k.lastPolledValidTo = k.clock.Copy()
}
if !newChannelClock.AnyAfter(k.lastPolledChannelClock) {
// No changes to channel clock - update validTo based on the new stable sequence
k.lastPolledValidTo.SetTo(stableClock)
// If we've exceeded empty poll count, return hasChanges=true to trigger the "is
// anyone listening" check
if totalPollCount > kMaxEmptyPollCount {
return true, false
} else {
return false, false
}
}
// The clock has changed - load the changes and store in last polled
if err := k.updateLastPolled(stableClock, newChannelClock); err != nil {
base.Warn("Error updating last polled for channel %s: %v", k.channelName, err)
return false, false
}
// We have changes - increment unread counter if we haven't already
if unreadPollCount == 0 {
atomic.AddUint32(&k.unreadPollCount, 1)
}
return true, false
}