Skip to content
This repository was archived by the owner on Mar 9, 2019. It is now read-only.

Commit 663b133

Browse files
committed
Clarify that Batch is only useful with concurrency
1 parent cda6f89 commit 663b133

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,14 @@ err := db.Batch(func(tx *bolt.Tx) error {
139139
})
140140
```
141141

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()`.
147150

148151
For example: don't display messages from inside the function, instead
149152
set variables in the enclosing scope:

batch.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ import (
1010
// Batch calls fn as part of a batch. It behaves similar to Update,
1111
// except:
1212
//
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.
1515
//
1616
// 2. the function passed to Batch may be called multiple times,
1717
// regardless of whether it returns error or not.
1818
//
1919
// This means that Batch function side effects must be idempotent and
2020
// take permanent effect only after a successful return is seen in
2121
// caller.
22+
//
23+
// Batch is only useful when there are multiple goroutines calling it.
2224
func (db *DB) Batch(fn func(*Tx) error) error {
2325
errCh := make(chan error, 1)
2426

0 commit comments

Comments
 (0)