-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsequencer.go
More file actions
37 lines (31 loc) · 847 Bytes
/
Copy pathsequencer.go
File metadata and controls
37 lines (31 loc) · 847 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
35
36
37
package lasr
import "github.com/boltdb/bolt"
// Sequencer returns an ID with each call to NextSequence and any error
// that occurred.
//
// A Sequencer should obey the following invariants:
//
// * NextSequence is goroutine-safe.
//
// * NextSequence will never generate the same ID.
//
// * NextSequence will return IDs whose big-endian binary representation is incrementing.
//
// Q is not guaranteed to use all of the IDs generated by its Sequencer.
type Sequencer interface {
NextSequence() (ID, error)
}
func (q *Q) nextSequence(tx *bolt.Tx) (ID, error) {
if q.seq != nil {
return q.seq.NextSequence()
}
return q.nextUint64ID(tx)
}
func (q *Q) nextUint64ID(tx *bolt.Tx) (Uint64ID, error) {
bucket := tx.Bucket(q.name)
seq, err := bucket.NextSequence()
if err != nil {
return Uint64ID(0), err
}
return Uint64ID(seq), nil
}