本文整理匯總了Golang中github.com/hashicorp/serf/serf.Query.Deadline方法的典型用法代碼示例。如果您正苦於以下問題:Golang Query.Deadline方法的具體用法?Golang Query.Deadline怎麽用?Golang Query.Deadline使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hashicorp/serf/serf.Query
的用法示例。
在下文中一共展示了Query.Deadline方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RegisterQuery
// RegisterQuery is used to register a pending query that may
// get a response. The ID of the query is returned
func (c *IPCClient) RegisterQuery(q *serf.Query) uint64 {
// Generate a unique-per-client ID
id := c.nextQueryID()
// Ensure the query deadline is in the future
timeout := q.Deadline().Sub(time.Now())
if timeout < 0 {
return id
}
// Register the query
c.queryLock.Lock()
c.pendingQueries[id] = q
c.queryLock.Unlock()
// Setup a timer to deregister after the timeout
time.AfterFunc(timeout, func() {
c.queryLock.Lock()
delete(c.pendingQueries, id)
c.queryLock.Unlock()
})
return id
}