-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfetchNewTx.go
More file actions
34 lines (29 loc) · 868 Bytes
/
fetchNewTx.go
File metadata and controls
34 lines (29 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main
import "github.com/garyburd/redigo/redis"
func fetchNewTx(unprocessedTxs chan<- string) {
conn := redisPool.Get()
defer conn.Close()
for {
select {
case <-done:
consoleLog.Notice(" [x] Finished watching", pendingTxKey)
return
default:
// Block until something is returned from redis, or timeout
r, err := redis.Values(conn.Do("BLPOP", pendingTxKey, pendingTxTimeout))
if err == redis.ErrNil {
consoleLog.Debug("No new entries in", pendingTxKey)
break
} else if err != nil {
failOnError(err, "Could not retrieve tx from redis")
}
// Convert reply to a string
// BLPOP returns [key, val] pairs
var key, tx string
_, err = redis.Scan(r, &key, &tx)
failOnError(err, "Could not convert transaction reply to string")
// Blocks until there's room to insert the tx
unprocessedTxs <- tx
}
}
}