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

Unified Diff: go/src/infra/gae/libs/wrapper/memory/context.go

Issue 1143053004: Simplify memory package interface. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: switch to blasters Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « go/src/infra/gae/libs/wrapper/gae/taskqueue.go ('k') | go/src/infra/gae/libs/wrapper/memory/datastore.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/gae/libs/wrapper/memory/context.go
diff --git a/go/src/infra/gae/libs/wrapper/memory/context.go b/go/src/infra/gae/libs/wrapper/memory/context.go
index a6b7eacaef111262856fc66025adfca15e6e5850..241d2a24edc1b09019731be9cb17c83c60b70005 100644
--- a/go/src/infra/gae/libs/wrapper/memory/context.go
+++ b/go/src/infra/gae/libs/wrapper/memory/context.go
@@ -5,6 +5,7 @@
package memory
import (
+ "errors"
"infra/gae/libs/wrapper"
"math/rand"
"sync"
@@ -92,18 +93,27 @@ func (m memContext) applyTxn(rnd *rand.Rand, txnCtxObj memContextObj) {
}
}
-// Enable adds a new memory context to c. This new memory context will have
-// a zeroed state.
-func Enable(c context.Context) context.Context {
- return context.WithValue(
+// Use adds implementations for the following gae/wrapper interfaces to the
+// context:
+// * wrapper.Datastore
+// * wrapper.TaskQueue
+// * wrapper.Memcache
+// * wrapper.GlobalInfo
+//
+// These can be retrieved with the "gae/wrapper".Get functions.
+//
+// The implementations are all backed by an in-memory implementation, and start
+// with an empty state.
+//
+// Using this more than once per context.Context will cause a panic.
+func Use(c context.Context) context.Context {
+ if c.Value(memContextKey) != nil {
+ panic(errors.New("memory.Use: called twice on the same Context"))
+ }
+ c = context.WithValue(
context.WithValue(c, memContextKey, newMemContext()),
giContextKey, &globalInfoData{})
-}
-
-// Use calls ALL of this packages Use* methods on c. This enables all
-// gae/wrapper Get* api's.
-func Use(c context.Context) context.Context {
- return UseTQ(UseDS(UseMC(UseGI(c))))
+ return useTQ(useDS(useMC(useGI(c))))
}
func cur(c context.Context) (p memContext) {
« no previous file with comments | « go/src/infra/gae/libs/wrapper/gae/taskqueue.go ('k') | go/src/infra/gae/libs/wrapper/memory/datastore.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698