scheduler

package module
v0.0.0-...-dc3105e Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2018 License: BSD-3-Clause Imports: 4 Imported by: 1

README

Build Status Coverage Status Go Report Card

Calls a function every N time.Duration

Example

package main

import (
        "fmt"
        "time"

        "github.com/epazote/scheduler"
)

func main() {
        // Create new scheduler
        s := scheduler.New()

        every := time.Second
        // Add a scheduled function
        s.AddScheduler("every second", every, func() {
                fmt.Println("Second passed")
        })

        // Let scheduler run for five seconds
        time.Sleep(5 * time.Second)

        // Stop the scheduled "every second" function
        err := s.Stop("every second")
        if err != nil {
                panic(err)
        }

        // Scheduler has now stopped
        time.Sleep(5 * time.Second)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Scheduler

type Scheduler struct {
	sync.Map
}

Scheduler map of schedulers

func New

func New() *Scheduler

New returns a new scheduler

func (*Scheduler) AddScheduler

func (s *Scheduler) AddScheduler(name string, interval time.Duration, f func())

AddScheduler calls a function every X defined interval

func (*Scheduler) Stop

func (s *Scheduler) Stop(name string) error

Stop ends and delete a specified scheduler.

func (*Scheduler) StopAll

func (s *Scheduler) StopAll()

StopAll ends all schedulers.

Jump to

Keyboard shortcuts

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