Documentation
¶
Overview ¶
Initially copied from Thanos
Copyright (c) The Thanos Authors. Licensed under the Apache License 2.0.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Repeat ¶
Repeat executes f every interval seconds until stopc is closed or f returns an error. It executes f once right after being called.
Example ¶
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/efficientgo/core/runutil"
)
func main() {
// It will stop Repeat 10 seconds later.
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// It will print out "Repeat" every 5 seconds.
err := runutil.Repeat(5*time.Second, ctx.Done(), func() error {
fmt.Println("Repeat")
return nil
})
if err != nil {
log.Fatal(err)
}
}
func Retry ¶
Retry executes f every interval seconds until timeout or no error is returned from f.
Example ¶
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/efficientgo/core/errors"
"github.com/efficientgo/core/runutil"
)
func main() {
// It will stop Retry 10 seconds later.
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// It will print out "Retry" every 5 seconds.
err := runutil.Retry(5*time.Second, ctx.Done(), func() error {
fmt.Println("Retry")
return errors.New("Try to retry")
})
if err != nil {
log.Fatal(err)
}
}
Types ¶
Click to show internal directories.
Click to hide internal directories.