@@ -14,24 +14,24 @@ import (
14
14
// Work manages a set of work items to be executed in parallel, at most once each.
15
15
// The items in the set must all be valid map keys.
16
16
type Work struct {
17
- f func (interface {} ) // function to run for each item
18
- running int // total number of runners
17
+ f func (any ) // function to run for each item
18
+ running int // total number of runners
19
19
20
20
mu sync.Mutex
21
- added map [interface {} ]bool // items added to set
22
- todo []interface {} // items yet to be run
23
- wait sync.Cond // wait when todo is empty
24
- waiting int // number of runners waiting for todo
21
+ added map [any ]bool // items added to set
22
+ todo []any // items yet to be run
23
+ wait sync.Cond // wait when todo is empty
24
+ waiting int // number of runners waiting for todo
25
25
}
26
26
27
27
func (w * Work ) init () {
28
28
if w .added == nil {
29
- w .added = make (map [interface {} ]bool )
29
+ w .added = make (map [any ]bool )
30
30
}
31
31
}
32
32
33
33
// Add adds item to the work set, if it hasn't already been added.
34
- func (w * Work ) Add (item interface {} ) {
34
+ func (w * Work ) Add (item any ) {
35
35
w .mu .Lock ()
36
36
w .init ()
37
37
if ! w .added [item ] {
@@ -51,7 +51,7 @@ func (w *Work) Add(item interface{}) {
51
51
// before calling Do (or else Do returns immediately),
52
52
// but it is allowed for f(item) to add new items to the set.
53
53
// Do should only be used once on a given Work.
54
- func (w * Work ) Do (n int , f func (item interface {} )) {
54
+ func (w * Work ) Do (n int , f func (item any )) {
55
55
if n < 1 {
56
56
panic ("par.Work.Do: n < 1" )
57
57
}
@@ -63,7 +63,7 @@ func (w *Work) Do(n int, f func(item interface{})) {
63
63
w .f = f
64
64
w .wait .L = & w .mu
65
65
66
- for i := 0 ; i < n - 1 ; i ++ {
66
+ for range n - 1 {
67
67
go w .runner ()
68
68
}
69
69
w .runner ()
@@ -110,13 +110,13 @@ type Cache struct {
110
110
type cacheEntry struct {
111
111
done uint32
112
112
mu sync.Mutex
113
- result interface {}
113
+ result any
114
114
}
115
115
116
116
// Do calls the function f if and only if Do is being called for the first time with this key.
117
117
// No call to Do with a given key returns until the one call to f returns.
118
118
// Do returns the value returned by the one call to f.
119
- func (c * Cache ) Do (key interface {} , f func () interface {}) interface {} {
119
+ func (c * Cache ) Do (key any , f func () any ) any {
120
120
entryIface , ok := c .m .Load (key )
121
121
if ! ok {
122
122
entryIface , _ = c .m .LoadOrStore (key , new (cacheEntry ))
@@ -136,7 +136,7 @@ func (c *Cache) Do(key interface{}, f func() interface{}) interface{} {
136
136
// Get returns the cached result associated with key.
137
137
// It returns nil if there is no such result.
138
138
// If the result for key is being computed, Get does not wait for the computation to finish.
139
- func (c * Cache ) Get (key interface {}) interface {} {
139
+ func (c * Cache ) Get (key any ) any {
140
140
entryIface , ok := c .m .Load (key )
141
141
if ! ok {
142
142
return nil
0 commit comments