This repository was archived by the owner on Mar 9, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -139,11 +139,14 @@ err := db.Batch(func(tx *bolt.Tx) error {
139
139
})
140
140
```
141
141
142
- Batch calls are opportunistically combined into larger transactions.
143
- The trade-off is that ` Batch ` can call the given function multiple
144
- times, if parts of the transaction fail. The function must be
145
- idempotent and side effects must take effect only after a successful
146
- return from ` DB.Batch() ` .
142
+ Concurrent Batch calls are opportunistically combined into larger
143
+ transactions. Batch is only useful when there are multiple goroutines
144
+ calling it.
145
+
146
+ The trade-off is that ` Batch ` can call the given
147
+ function multiple times, if parts of the transaction fail. The
148
+ function must be idempotent and side effects must take effect only
149
+ after a successful return from ` DB.Batch() ` .
147
150
148
151
For example: don't display messages from inside the function, instead
149
152
set variables in the enclosing scope:
Original file line number Diff line number Diff line change @@ -10,15 +10,17 @@ import (
10
10
// Batch calls fn as part of a batch. It behaves similar to Update,
11
11
// except:
12
12
//
13
- // 1. multiple Batch function calls can be combined into a single
14
- // Bolt transaction.
13
+ // 1. concurrent Batch calls can be combined into a single Bolt
14
+ // transaction.
15
15
//
16
16
// 2. the function passed to Batch may be called multiple times,
17
17
// regardless of whether it returns error or not.
18
18
//
19
19
// This means that Batch function side effects must be idempotent and
20
20
// take permanent effect only after a successful return is seen in
21
21
// caller.
22
+ //
23
+ // Batch is only useful when there are multiple goroutines calling it.
22
24
func (db * DB ) Batch (fn func (* Tx ) error ) error {
23
25
errCh := make (chan error , 1 )
24
26
You can’t perform that action at this time.
0 commit comments