gon

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2019 License: MIT Imports: 2 Imported by: 4 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

gon Build Status

Fire and forget timer/ticker scheduling.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alarm

type Alarm struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Alarm runs a single function once.

func NewAlarm

func NewAlarm(d time.Duration, aid int64, af EventFunc) *Alarm

NewAlarm creates the Alarm structure and quit channel.

func (*Alarm) Start

func (a *Alarm) Start()

Start creates a one-shot timer and runs it after its duration has passed. If the alarm is a repeating alarm, a 24-hour Ticker is created.

func (*Alarm) Stop

func (a *Alarm) Stop()

Stop and remove the alarm.

func (*Alarm) Wait

func (a *Alarm) Wait()

Wait for the event to finish.

type EventFunc

type EventFunc func(int64)

EventFunc is the signature of the ticker/alarm callbacks.

type Scheduler

type Scheduler struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Scheduler holds pointers to all the tickers and timers.

func NewScheduler

func NewScheduler() *Scheduler

NewScheduler returns a Scheduler populated with maps.

func (*Scheduler) AddAlarmAt

func (sc *Scheduler) AddAlarmAt(t time.Time, f EventFunc, repeat bool)

AddAlarmAt triggers functions at a specific time of day.

func (*Scheduler) AddAlarmIn

func (sc *Scheduler) AddAlarmIn(d time.Duration, f EventFunc)

AddAlarmIn triggers functions after a specific duration has passed.

func (*Scheduler) RemoveAlarm

func (sc *Scheduler) RemoveAlarm(id int64)

RemoveAlarm removes an alarm by id, stopping it if necessary.

func (*Scheduler) RemoveTicker

func (sc *Scheduler) RemoveTicker(d time.Duration)

RemoveTicker removes a ticker by duration, stopping it if necessary.

func (*Scheduler) RepeatHours

func (sc *Scheduler) RepeatHours(n int, f EventFunc)

RepeatHours adds a repeating task on an hour-based interval.

func (*Scheduler) RepeatMinutes

func (sc *Scheduler) RepeatMinutes(n int, f EventFunc)

RepeatMinutes adds a repeating task on a minute-based interval.

func (*Scheduler) RepeatSeconds

func (sc *Scheduler) RepeatSeconds(n int, f EventFunc)

RepeatSeconds adds a repeating task based on a seconds interval.

func (*Scheduler) Wait

func (sc *Scheduler) Wait()

Wait for all waitgroups in tickers and alarms.

type Ticker

type Ticker struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Ticker runs one or more functions, repeating at an interval.

func NewTicker

func NewTicker(d time.Duration) *Ticker

NewTicker creates the Ticker structure and quit channel.

func (*Ticker) AddFunc

func (t *Ticker) AddFunc(f EventFunc, id int64)

AddFunc adds another callback to the funcs map with a new ID.

func (*Ticker) Start

func (t *Ticker) Start()

Start creates the time.Ticker and handles the calls at intervals.

func (*Ticker) Stop

func (t *Ticker) Stop()

Stop the ticker.

func (*Ticker) Wait

func (t *Ticker) Wait()

Wait for the current scheduled task in the ticker to finish.

Directories

Path Synopsis
examples
simple command

Jump to

Keyboard shortcuts

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