generated from hashicorp/packer-plugin-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #249 from mkumatag/fix_get_instance
Add polling for the get instance
- Loading branch information
Showing
2 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package powervs | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
// pollUntil validates if a certain condition is met at defined poll intervals. | ||
// If a timeout is reached, an associated error is returned to the caller. | ||
// condition contains the use-case specific code that returns true when a certain condition is achieved. | ||
func pollUntil(pollInterval, timeOut <-chan time.Time, condition func() (bool, error)) error { | ||
for { | ||
select { | ||
case <-timeOut: | ||
return fmt.Errorf("timed out while waiting for job to complete") | ||
case <-pollInterval: | ||
if done, err := condition(); err != nil { | ||
return err | ||
} else if done { | ||
return nil | ||
} | ||
} | ||
} | ||
} |