本文整理匯總了Golang中github.com/dancannon/gorethink.Cursor.Listen方法的典型用法代碼示例。如果您正苦於以下問題:Golang Cursor.Listen方法的具體用法?Golang Cursor.Listen怎麽用?Golang Cursor.Listen使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/dancannon/gorethink.Cursor
的用法示例。
在下文中一共展示了Cursor.Listen方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: changeFeedHelper
func changeFeedHelper(cursor *r.Cursor, changeEventName string,
send chan<- Message, stop <-chan bool) {
change := make(chan r.ChangeResponse)
cursor.Listen(change)
for {
eventName := ""
var data interface{}
select {
case <-stop:
cursor.Close()
return
case val := <-change:
if val.NewValue != nil && val.OldValue == nil {
eventName = changeEventName + " add"
data = val.NewValue
} else if val.NewValue == nil && val.OldValue != nil {
eventName = changeEventName + " remove"
data = val.OldValue
} else if val.NewValue != nil && val.OldValue != nil {
eventName = changeEventName + " edit"
data = val.NewValue
}
send <- Message{eventName, data}
}
}
}
示例2: createSubscription
func createSubscription(cursor *r.Cursor, client *Client, entityName string, stopKey int) {
recordChan := make(chan r.ChangeResponse)
cursor.Listen(recordChan)
stopChan := client.NewStopChannel(stopKey)
go func() {
for {
select {
case <-stopChan:
cursor.Close()
return
case change := <-recordChan:
var command string
var data interface{}
if change.NewValue != nil && change.OldValue == nil {
command = entityName + " add"
data = change.NewValue
}
if change.NewValue == nil && change.OldValue != nil {
command = entityName + " remove"
data = change.OldValue
fmt.Println("sent '" + entityName + " remove' msg")
}
if change.NewValue != nil && change.OldValue != nil {
command = entityName + " edit"
data = change.NewValue
}
client.send <- SocketMessage{command, data}
fmt.Println("sent '"+command+"' msg ", data)
}
}
}()
}