loop

package
v0.0.0-...-bcea9b7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2021 License: MIT Imports: 3 Imported by: 0

README

Usage

Looper executes the provided function once in while and collects any errors.

Example

package main 

import (
	"github.com/donutloop/toolkit/looper"
	"log"
)


func main() {
	l := loop.NewLooper(1*time.Millisecond, func() error {
		// do things
		return nil
	})

	for err := range l.Error() {
		log.Println(err)
	}
	
	// stop call is missing
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Looper

type Looper struct {
	// contains filtered or unexported fields
}
Example
package main

import (
	"fmt"
	"time"

	"github.com/donutloop/toolkit/loop"
)

func main() {
	loop.NewLooper(1*time.Second, func() error {
		// do after one second things
		return nil
	})

	// error and stop handling is missing for simplicity

	fmt.Println("successfully")
}
Output:

successfully

func NewLooper

func NewLooper(rate time.Duration, event func() error) *Looper

func (*Looper) Error

func (l *Looper) Error() <-chan error

func (*Looper) Stop

func (l *Looper) Stop()

type RecoverError

type RecoverError struct {
	Err   interface{}
	Stack []byte
}

func (*RecoverError) Error

func (e *RecoverError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL