@@ -22,10 +22,10 @@ import (
2222)
2323
2424func TestDo (t * testing.T ) {
25- var g singleflight.Group
25+ var g singleflight.Group [ string , string ]
2626
2727 want := "val"
28- got , shared , err := g .Do (context .Background (), "key" , func (_ context.Context ) (interface {} , error ) {
28+ got , shared , err := g .Do (context .Background (), "key" , func (_ context.Context ) (string , error ) {
2929 return want , nil
3030 })
3131 if err != nil {
@@ -40,21 +40,21 @@ func TestDo(t *testing.T) {
4040}
4141
4242func TestDo_error (t * testing.T ) {
43- var g singleflight.Group
43+ var g singleflight.Group [ string , string ]
4444 wantErr := errors .New ("test error" )
45- got , _ , err := g .Do (context .Background (), "key" , func (_ context.Context ) (interface {} , error ) {
46- return nil , wantErr
45+ got , _ , err := g .Do (context .Background (), "key" , func (_ context.Context ) (string , error ) {
46+ return "" , wantErr
4747 })
4848 if err != wantErr {
4949 t .Errorf ("got error %v, want %v" , err , wantErr )
5050 }
51- if got != nil {
51+ if got != "" {
5252 t .Errorf ("unexpected value %#v" , got )
5353 }
5454}
5555
5656func TestDo_multipleCalls (t * testing.T ) {
57- var g singleflight.Group
57+ var g singleflight.Group [ string , string ]
5858
5959 want := "val"
6060 var counter int32
@@ -68,7 +68,7 @@ func TestDo_multipleCalls(t *testing.T) {
6868 for i := 0 ; i < n ; i ++ {
6969 go func (i int ) {
7070 defer wg .Done ()
71- got [i ], shared [i ], err [i ] = g .Do (context .Background (), "key" , func (_ context.Context ) (interface {} , error ) {
71+ got [i ], shared [i ], err [i ] = g .Do (context .Background (), "key" , func (_ context.Context ) (string , error ) {
7272 atomic .AddInt32 (& counter , 1 )
7373 time .Sleep (100 * time .Millisecond )
7474 return want , nil
@@ -95,11 +95,11 @@ func TestDo_multipleCalls(t *testing.T) {
9595}
9696
9797func TestDo_callRemoval (t * testing.T ) {
98- var g singleflight.Group
98+ var g singleflight.Group [ string , string ]
9999
100100 wantPrefix := "val"
101101 counter := 0
102- fn := func (_ context.Context ) (interface {} , error ) {
102+ fn := func (_ context.Context ) (string , error ) {
103103 counter ++
104104 return wantPrefix + strconv .Itoa (counter ), nil
105105 }
@@ -131,7 +131,7 @@ func TestDo_cancelContext(t *testing.T) {
131131 done := make (chan struct {})
132132 defer close (done )
133133
134- var g singleflight.Group
134+ var g singleflight.Group [ string , string ]
135135
136136 want := "val"
137137 ctx , cancel := context .WithCancel (context .Background ())
@@ -140,7 +140,7 @@ func TestDo_cancelContext(t *testing.T) {
140140 cancel ()
141141 }()
142142 start := time .Now ()
143- got , shared , err := g .Do (ctx , "key" , func (_ context.Context ) (interface {} , error ) {
143+ got , shared , err := g .Do (ctx , "key" , func (_ context.Context ) (string , error ) {
144144 select {
145145 case <- time .After (time .Second ):
146146 case <- done :
@@ -156,7 +156,7 @@ func TestDo_cancelContext(t *testing.T) {
156156 if shared {
157157 t .Error ("the value should not be shared" )
158158 }
159- if got != nil {
159+ if got != "" {
160160 t .Errorf ("unexpected value %#v" , got )
161161 }
162162}
@@ -165,10 +165,10 @@ func TestDo_cancelContextSecond(t *testing.T) {
165165 done := make (chan struct {})
166166 defer close (done )
167167
168- var g singleflight.Group
168+ var g singleflight.Group [ string , string ]
169169
170170 want := "val"
171- fn := func (_ context.Context ) (interface {} , error ) {
171+ fn := func (_ context.Context ) (string , error ) {
172172 select {
173173 case <- time .After (time .Second ):
174174 case <- done :
@@ -196,7 +196,7 @@ func TestDo_cancelContextSecond(t *testing.T) {
196196 if ! shared {
197197 t .Error ("the value should be shared" )
198198 }
199- if got != nil {
199+ if got != "" {
200200 t .Errorf ("unexpected value %#v" , got )
201201 }
202202}
@@ -205,12 +205,12 @@ func TestForget(t *testing.T) {
205205 done := make (chan struct {})
206206 defer close (done )
207207
208- var g singleflight.Group
208+ var g singleflight.Group [ string , string ]
209209
210210 wantPrefix := "val"
211211 var counter uint64
212212 firstCall := make (chan struct {})
213- fn := func (_ context.Context ) (interface {} , error ) {
213+ fn := func (_ context.Context ) (string , error ) {
214214 c := atomic .AddUint64 (& counter , 1 )
215215 if c == 1 {
216216 close (firstCall )
@@ -252,7 +252,7 @@ func TestDo_multipleCallsCanceled(t *testing.T) {
252252 done := make (chan struct {})
253253 defer close (done )
254254
255- var g singleflight.Group
255+ var g singleflight.Group [ string , string ]
256256
257257 var counter int32
258258
@@ -271,7 +271,7 @@ func TestDo_multipleCallsCanceled(t *testing.T) {
271271 contexts [i ] = ctx
272272 cancelFuncs [i ] = cancel
273273 mu .Unlock ()
274- _ , _ , _ = g .Do (ctx , "key" , func (ctx context.Context ) (interface {} , error ) {
274+ _ , _ , _ = g .Do (ctx , "key" , func (ctx context.Context ) (string , error ) {
275275 atomic .AddInt32 (& counter , 1 )
276276 close (fnCalled )
277277 var err error
@@ -288,7 +288,7 @@ func TestDo_multipleCallsCanceled(t *testing.T) {
288288
289289 fnErrChan <- err
290290
291- return nil , nil
291+ return "" , nil
292292 })
293293 }(i )
294294 }
0 commit comments