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

Side by Side Diff: common/meter/config.go

Issue 1679023005: Add Context cancellation to clock. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Actually upload the patch. Created 4 years, 10 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 | « common/gcloud/pubsub/subscriber/subscriber.go ('k') | common/meter/config_test.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 Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package meter
6
7 import (
8 "time"
9 )
10
11 const (
12 // The size of the work ingest channel (Add, AddWait), which holds work until
13 // it's dequeued by the consumeWork loop.
14 defaultAddBufferSize = 16
15 )
16
17 // Config is the set of meter configuration parameters.
18 type Config struct {
19 // Count is the maximum number of work items to buffer before automatica lly
20 // flushing.
21 Count int
22 // Delay is the maximum amount of time to wait after an element has been
23 // buffered before automatically flushing it.
24 Delay time.Duration
25
26 // AddBufferSize is the size of the work ingest channel buffer. If zero, a
27 // default size will be used.
28 AddBufferSize int
29
30 // Callback is the work callback method that is invoked with flushed Met er work.
31 //
32 // All callback invocations are made from the same goroutine, and thus
33 // synchronous with each other. Therefore, any non-trivial work that nee ds to be
34 // done based on the callback must be handled in a separate goroutine.
35 Callback func([]interface{})
36
37 // IngestCallback is a callback method that is invoked when the meter in gests
38 // a new unit of work. If it returns true, a flush will be triggered. Th is is
39 // intended to facilitate external accounting.
40 //
41 // All callback invocations are made from the same goroutine, and thus
42 // synchronous with each other.
43 IngestCallback func(interface{}) bool
44 }
45
46 // HasFlushConstraints tests if the current configuration applies any flushing
47 // constraints. A meter without flush constraints will flush after each message.
48 func (c *Config) HasFlushConstraints() bool {
49 return (c.Count != 0 || c.Delay != 0)
50 }
51
52 // getAddBufferSize returns the configuration's AddBufferSize property, or the
53 // default work buffer size if the property value is zero.
54 func (c *Config) getAddBufferSize() int {
55 if c.AddBufferSize == 0 {
56 return defaultAddBufferSize
57 }
58 return c.AddBufferSize
59 }
OLDNEW
« no previous file with comments | « common/gcloud/pubsub/subscriber/subscriber.go ('k') | common/meter/config_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698