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

Make Sleep check for cancelled context every second #798

Merged
merged 3 commits into from
Aug 8, 2019

Conversation

juanjux
Copy link
Contributor

@juanjux juanjux commented Aug 7, 2019

Fixes #797

Signed-off-by: Juanjo Alvarez juanjo@sourced.tech

Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>
@juanjux
Copy link
Contributor Author

juanjux commented Aug 7, 2019

Updated to use better solution by @creachadair, thanks!

@juanjux juanjux requested a review from a team August 7, 2019 17:23
@juanjux juanjux self-assigned this Aug 7, 2019
Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>

Fix time scale

Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>

Multiply duration for sleep inside the parents

Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>

Multiply duration for sleep inside the parents

Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>
time.Sleep(time.Duration(child.(float64)*1000) * time.Millisecond)
return 0, nil
select {
case <-time.After(time.Duration(child.(float64) * 1000) * time.Millisecond):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would create a timer using time.NewTimer instead and then defer timer.Stop() so that we don't leave potentially long-running timers running unnecessarily.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

sql/expression/function/sleep.go Show resolved Hide resolved
sql/expression/function/sleep.go Outdated Show resolved Hide resolved
Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>
@ajnavarro ajnavarro merged commit 4eaee9b into src-d:master Aug 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sleep function cannot be cancelled
4 participants