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

Side by Side Diff: go/src/infra/gae/libs/wrapper/mathrand.go

Issue 1230303003: Revert "Refactor current GAE abstraction library to be free of the SDK*" (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years, 5 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 | « go/src/infra/gae/libs/wrapper/globalinfo.go ('k') | go/src/infra/gae/libs/wrapper/memcache.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package gae 5 package wrapper
6 6
7 import ( 7 import (
8 "golang.org/x/net/context"
9 "math/rand" 8 "math/rand"
10 9
11 » "github.com/luci/luci-go/common/clock" 10 » "golang.org/x/net/context"
11 » "infra/libs/clock"
12 ) 12 )
13 13
14 // MathRandFactory is the function signature for factory methods compatible with 14 // MathRandFactory is the function signature for factory methods compatible with
15 // SetMathRandFactory. 15 // SetMathRandFactory.
16 type MathRandFactory func(context.Context) *rand.Rand 16 type MathRandFactory func(context.Context) *rand.Rand
17 17
18 // GetMathRand gets a *"math/rand".Rand from the context. If one hasn't been 18 // GetMathRand gets a *"math/rand".Rand from the context. If one hasn't been
19 // set, this creates a new Rand object with a Source initialized from the 19 // set, this creates a new Rand object with a Source initialized from the
20 // current time clock.Now(c).UnixNano(). 20 // current time clock.Now(c).UnixNano().
21 func GetMathRand(c context.Context) *rand.Rand { 21 func GetMathRand(c context.Context) *rand.Rand {
(...skipping 11 matching lines...) Expand all
33 33
34 // SetMathRand sets the current *"math/rand".Rand object in the context. Useful 34 // SetMathRand sets the current *"math/rand".Rand object in the context. Useful
35 // for testing with a quick mock. This is just a shorthand SetMathRandFactory 35 // for testing with a quick mock. This is just a shorthand SetMathRandFactory
36 // invocation to set a factory which always returns the same object. 36 // invocation to set a factory which always returns the same object.
37 func SetMathRand(c context.Context, r *rand.Rand) context.Context { 37 func SetMathRand(c context.Context, r *rand.Rand) context.Context {
38 if r == nil { 38 if r == nil {
39 return SetMathRandFactory(c, nil) 39 return SetMathRandFactory(c, nil)
40 } 40 }
41 return SetMathRandFactory(c, func(context.Context) *rand.Rand { return r }) 41 return SetMathRandFactory(c, func(context.Context) *rand.Rand { return r })
42 } 42 }
OLDNEW
« no previous file with comments | « go/src/infra/gae/libs/wrapper/globalinfo.go ('k') | go/src/infra/gae/libs/wrapper/memcache.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698