Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
32956b7d
Commit
32956b7d
authored
Nov 05, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #16829 from mikedanese/until-immediate
Auto commit by PR queue bot
parents
919d2c11
8b980929
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
6 deletions
+23
-6
util.go
pkg/util/util.go
+11
-6
util_test.go
pkg/util/util_test.go
+12
-0
No files found.
pkg/util/util.go
View file @
32956b7d
...
@@ -114,17 +114,22 @@ func Forever(f func(), period time.Duration) {
...
@@ -114,17 +114,22 @@ func Forever(f func(), period time.Duration) {
// stop channel is already closed. Pass NeverStop to Until if you
// stop channel is already closed. Pass NeverStop to Until if you
// don't want it stop.
// don't want it stop.
func
Until
(
f
func
(),
period
time
.
Duration
,
stopCh
<-
chan
struct
{})
{
func
Until
(
f
func
(),
period
time
.
Duration
,
stopCh
<-
chan
struct
{})
{
select
{
case
<-
stopCh
:
return
default
:
}
for
{
for
{
select
{
case
<-
stopCh
:
return
default
:
}
func
()
{
func
()
{
defer
HandleCrash
()
defer
HandleCrash
()
f
()
f
()
}()
}()
time
.
Sleep
(
period
)
select
{
case
<-
stopCh
:
return
case
<-
time
.
After
(
period
)
:
}
}
}
}
}
...
...
pkg/util/util_test.go
View file @
32956b7d
...
@@ -24,6 +24,7 @@ import (
...
@@ -24,6 +24,7 @@ import (
"reflect"
"reflect"
"strings"
"strings"
"testing"
"testing"
"time"
"github.com/ghodss/yaml"
"github.com/ghodss/yaml"
)
)
...
@@ -48,6 +49,17 @@ func TestUntil(t *testing.T) {
...
@@ -48,6 +49,17 @@ func TestUntil(t *testing.T) {
<-
called
<-
called
}
}
func
TestUntilReturnsImmediately
(
t
*
testing
.
T
)
{
now
:=
time
.
Now
()
ch
:=
make
(
chan
struct
{})
Until
(
func
()
{
close
(
ch
)
},
30
*
time
.
Second
,
ch
)
if
now
.
Add
(
25
*
time
.
Second
)
.
Before
(
time
.
Now
())
{
t
.
Errorf
(
"Until did not return immediately when the stop chan was closed inside the func"
)
}
}
func
TestHandleCrash
(
t
*
testing
.
T
)
{
func
TestHandleCrash
(
t
*
testing
.
T
)
{
count
:=
0
count
:=
0
expect
:=
10
expect
:=
10
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment