Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: service/datastore/transaction.go

Issue 2302743002: Interface update, per-method Contexts. (Closed)
Patch Set: Lightning talk licenses. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « service/datastore/size_test.go ('k') | service/info/context.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package datastore
6
7 import (
8 "golang.org/x/net/context"
9 )
10
11 // Transaction is a generic interface used to describe a Datastore transaction.
12 //
13 // The nil Transaction represents no transaction context.
14 //
15 // TODO: Add some functionality here. Ideas include:
16 // - Active() bool: is the transaction currently active?
17 // - AffectedGroups() []*ds.Key: list the groups that have been referenced in
18 // this Transaction so far.
19 type Transaction interface{}
20
21 // WithoutTransaction returns a Context that isn't bound to a transaction.
22 // This may be called even when outside of a transaction, in which case the
23 // input Context is a valid return value.
24 //
25 // This can be useful to perform non-transactional tasks given only a Context
26 // that is bound to a transaction.
27 func WithoutTransaction(c context.Context) context.Context {
28 raw := Raw(c)
29 if t := raw.CurrentTransaction(); t == nil {
30 // If we're not in a transaction, return the input Contxt.
31 return c
32 }
33 return raw.WithoutTransaction()
34 }
35
36 // CurrentTransaction returns a reference to the current Transaction, or nil
37 // if the Context does not have a current Transaction.
38 func CurrentTransaction(c context.Context) Transaction {
39 return Raw(c).CurrentTransaction()
40 }
OLDNEW
« no previous file with comments | « service/datastore/size_test.go ('k') | service/info/context.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698