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
2816632c
Commit
2816632c
authored
Aug 17, 2015
by
Marek Grabowski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11996 from jayunit100/maxTimes
Fix maxTimes comment to clarify infinit waits
parents
850b9829
3b295ee3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
4 deletions
+9
-4
wait.go
pkg/util/wait/wait.go
+7
-3
wait_test.go
pkg/util/wait/wait_test.go
+2
-1
No files found.
pkg/util/wait/wait.go
View file @
2816632c
...
...
@@ -43,14 +43,18 @@ type ConditionFunc func() (done bool, err error)
// Poll tries a condition func until it returns true, an error, or the timeout
// is reached. condition will always be invoked at least once but some intervals
// may be missed if the condition takes too long or the time window is too short.
// If you pass maxTimes = 0, Poll will loop until condition returns true or an
// error.
// If you want to Poll something forever, see PollInfinite.
// Poll always waits the interval before the first check of the condition.
// TODO: create a separate PollImmediate function that does not wait.
func
Poll
(
interval
,
timeout
time
.
Duration
,
condition
ConditionFunc
)
error
{
return
WaitFor
(
poller
(
interval
,
timeout
),
condition
)
}
// PollInfinite polls forever.
func
PollInfinite
(
interval
time
.
Duration
,
condition
ConditionFunc
)
error
{
return
WaitFor
(
poller
(
interval
,
0
),
condition
)
}
// WaitFunc creates a channel that receives an item every time a test
// should be executed and is closed when the last test should be invoked.
type
WaitFunc
func
()
<-
chan
struct
{}
...
...
@@ -81,7 +85,7 @@ func WaitFor(wait WaitFunc, c ConditionFunc) error {
// poller returns a WaitFunc that will send to the channel every
// interval until timeout has elapsed and then close the channel.
// Over very short intervals you may receive no ticks before
// the channel is closed
closed. If maxTimes
is 0, the channel
// the channel is closed
. If timeout
is 0, the channel
// will never be closed.
func
poller
(
interval
,
timeout
time
.
Duration
)
WaitFunc
{
return
WaitFunc
(
func
()
<-
chan
struct
{}
{
...
...
pkg/util/wait/wait_test.go
View file @
2816632c
...
...
@@ -91,9 +91,10 @@ func TestPollForever(t *testing.T) {
}
return
false
,
nil
})
if
err
:=
Poll
(
time
.
Microsecond
,
0
,
f
);
err
!=
nil
{
if
err
:=
Poll
Infinite
(
time
.
Microsecond
,
f
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error %v"
,
err
)
}
close
(
ch
)
complete
<-
struct
{}{}
}()
...
...
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