-
Notifications
You must be signed in to change notification settings - Fork 199
/
serialActions.go
65 lines (51 loc) · 933 Bytes
/
serialActions.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package leveldb
import (
"github.com/ElrondNetwork/elrond-go/storage"
"github.com/syndtr/goleveldb/leveldb/opt"
)
type putBatchAct struct {
batch *batch
resChan chan<- error
}
type pairResult struct {
value []byte
err error
}
type serialQueryer interface {
request(s *SerialDB)
}
type getAct struct {
key []byte
resChan chan<- *pairResult
}
type hasAct struct {
key []byte
resChan chan<- error
}
func (p *putBatchAct) request(s *SerialDB) {
wopt := &opt.WriteOptions{
Sync: true,
}
err := s.db.Write(p.batch.batch, wopt)
p.resChan <- err
}
func (g *getAct) request(s *SerialDB) {
data, err := s.db.Get(g.key, nil)
res := &pairResult{
value: data,
err: err,
}
g.resChan <- res
}
func (h *hasAct) request(s *SerialDB) {
has, err := s.db.Has(h.key, nil)
if err != nil {
h.resChan <- err
return
}
if has {
h.resChan <- nil
return
}
h.resChan <- storage.ErrKeyNotFound
}