package timerrun

import (
	"time"

	"github.com/sirupsen/logrus"
)

func Run(d time.Duration, targetFun func() error) {
	for {
		func() {
			defer func() {
				if r := recover(); r != nil {
					logrus.Error(r)
				}
			}()

			err := targetFun()
			if err != nil {
				logrus.Error(err)
			}
		}()

		<-time.After(d)
	}
}
