Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit 390e2a8

Browse files
author
Juanjo Alvarez
committed
Sleep: use timers and return context.Canceled in ctx.Done()
Signed-off-by: Juanjo Alvarez <[email protected]>
1 parent ebdf5a7 commit 390e2a8

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

sql/expression/function/sleep.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package function
22

33
import (
4+
"context"
45
"fmt"
5-
"time"
6-
76
"github.com/src-d/go-mysql-server/sql"
87
"github.com/src-d/go-mysql-server/sql/expression"
8+
"time"
99
)
1010

1111
// Sleep is a function that just waits for the specified number of seconds
@@ -37,10 +37,13 @@ func (s *Sleep) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
3737
return nil, err
3838
}
3939

40+
t := time.NewTimer(time.Duration(child.(float64) * 1000) * time.Millisecond)
41+
defer t.Stop()
42+
4043
select {
41-
case <-time.After(time.Duration(child.(float64) * 1000) * time.Millisecond):
42-
return 0, nil
4344
case <-ctx.Done():
45+
return context.Canceled, nil
46+
case <-t.C:
4447
return 0, nil
4548
}
4649
}

0 commit comments

Comments
 (0)