Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cron ¶
type Cron struct {
// contains filtered or unexported fields
}
Cron
Example ¶
package main import ( "fmt" "github.com/name5566/leaf/timer" ) func main() { d := timer.NewDispatcher(10) // cron expr cronExpr, err := timer.NewCronExpr("* * * * * *") if err != nil { return } // cron var c *timer.Cron c = d.CronFunc(cronExpr, func() { fmt.Println("My name is Leaf") c.Stop() }) // dispatch (<-d.ChanTimer).Cb() }
Output: My name is Leaf
type CronExpr ¶
type CronExpr struct {
// contains filtered or unexported fields
}
Field name | Mandatory? | Allowed values | Allowed special characters ---------- | ---------- | -------------- | -------------------------- Seconds | No | 0-59 | * / , - Minutes | Yes | 0-59 | * / , - Hours | Yes | 0-23 | * / , - Day of month | Yes | 1-31 | * / , - Month | Yes | 1-12 | * / , - Day of week | Yes | 0-6 | * / , -
Example ¶
package main import ( "fmt" "github.com/name5566/leaf/timer" "time" ) func main() { cronExpr, err := timer.NewCronExpr("0 * * * *") if err != nil { return } fmt.Println(cronExpr.Next(time.Date( 2000, 1, 1, 20, 10, 5, 0, time.UTC, ))) }
Output: 2000-01-01 21:00:00 +0000 UTC
type Dispatcher ¶
type Dispatcher struct {
ChanTimer chan *Timer
}
one dispatcher per goroutine (goroutine not safe)
func NewDispatcher ¶
func NewDispatcher(l int) *Dispatcher
func (*Dispatcher) CronFunc ¶
func (disp *Dispatcher) CronFunc(cronExpr *CronExpr, _cb func()) *Cron
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer
Example ¶
package main import ( "fmt" "github.com/name5566/leaf/timer" ) func main() { d := timer.NewDispatcher(10) // timer 1 d.AfterFunc(1, func() { fmt.Println("My name is Leaf") }) // timer 2 t := d.AfterFunc(1, func() { fmt.Println("will not print") }) t.Stop() // dispatch (<-d.ChanTimer).Cb() }
Output: My name is Leaf
Click to show internal directories.
Click to hide internal directories.