Documentation ¶
Overview ¶
Package waitabit provides functionality for handling system interrupts.
Index ¶
- type Wait
- func (w *Wait) Wait()
- func (w *Wait) WaitWithFunc(function func())
- func (w *Wait) WaitWithFuncErr(function func() error) error
- func (w *Wait) WaitWithTimeout(timeout time.Duration)
- func (w *Wait) WaitWithTimeoutAndFunc(timeout time.Duration, function func())
- func (w *Wait) WaitWithTimeoutAndFuncErr(timeout time.Duration, function func() error) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Wait ¶
type Wait struct {
// contains filtered or unexported fields
}
Wait struct represent wait functionality.
func (*Wait) Wait ¶
func (w *Wait) Wait()
Wait simply wait for interruption.
Example ¶
wait := NewWait(os.Interrupt) wait.Wait() fmt.Println("Bye")
Output: Bye
func (*Wait) WaitWithFunc ¶
func (w *Wait) WaitWithFunc(function func())
WaitWithFunc receive function as argument and call Wait() to wait interrupt signal. The function will be called after Wait().
Example ¶
wait := NewWait(os.Interrupt) wait.WaitWithFunc(func() { // your logic here fmt.Println("Bye") })
Output: Bye
func (*Wait) WaitWithFuncErr ¶
WaitWithFuncErr receive function as argument and call Wait() to wait interrupt signal. The function will be called after Wait(). If function return an error it would be wrapped and returned.
Example ¶
wait := NewWait(os.Interrupt) if err := wait.WaitWithFuncErr(func() error { // your logic here return fmt.Errorf("something went wrong") }); err != nil { fmt.Println("something bad happened:", err) } fmt.Println("Bye")
Output: Bye
func (*Wait) WaitWithTimeout ¶
WaitWithTimeout wait a given amount fo time and then exit.
Example ¶
wait := NewWait(os.Interrupt) wait.WaitWithTimeout(1 * time.Second) fmt.Println("Bye")
Output: Bye
func (*Wait) WaitWithTimeoutAndFunc ¶
WaitWithTimeoutAndFunc wait a given amount of time then call function and then exit.
Example ¶
wait := NewWait(os.Interrupt) wait.WaitWithTimeoutAndFunc(1*time.Second, func() { // your logic here fmt.Println("Bye") })
Output: Bye
func (*Wait) WaitWithTimeoutAndFuncErr ¶
WaitWithTimeoutAndFunc wait a given amount of call function and then exit. If function return an error it would be wrapped and returned.
Example ¶
wait := NewWait(os.Interrupt) if err := wait.WaitWithTimeoutAndFuncErr(1*time.Second, func() error { // your logic here return fmt.Errorf("something went wrong") }); err != nil { fmt.Println("something bad happened:", err) } fmt.Println("Bye")
Output: Bye