Skip to content

Latest commit

 

History

History
42 lines (32 loc) · 1.12 KB

File metadata and controls

42 lines (32 loc) · 1.12 KB

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)
}