File tree 1 file changed +22
-7
lines changed
1 file changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -334,13 +334,28 @@ func ExampleClient_Idle() {
334
334
if err != nil {
335
335
log .Fatalf ("IDLE command failed: %v" , err )
336
336
}
337
-
338
- // Wait for 30s to receive updates from the server
339
- time .Sleep (30 * time .Second )
340
-
341
- // Stop idling
342
- if err := idleCmd .Close (); err != nil {
343
- log .Fatalf ("failed to stop idling: %v" , err )
337
+ defer idleCmd .Close ()
338
+
339
+ done := make (chan error , 1 )
340
+ go func () {
341
+ done <- idleCmd .Wait ()
342
+ }()
343
+
344
+ // Wait for 30s to receive updates from the server, then stop idling
345
+ t := time .NewTimer (30 * time .Second )
346
+ defer t .Stop ()
347
+ select {
348
+ case <- t .C :
349
+ if err := idleCmd .Close (); err != nil {
350
+ log .Fatalf ("failed to stop idling: %v" , err )
351
+ }
352
+ if err := <- done ; err != nil {
353
+ log .Fatalf ("IDLE command failed: %v" , err )
354
+ }
355
+ case err := <- done :
356
+ if err != nil {
357
+ log .Fatalf ("IDLE command failed: %v" , err )
358
+ }
344
359
}
345
360
}
346
361
You can’t perform that action at this time.
0 commit comments