Skip to content

wangh10/timer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

timer

timer handle some task

Install

go get github.com/wangh10/timer

Usage

There are three tasks which need handle: t1 handle after 1s, t2 handle after 3s, t3 handle after 5s.

package main

import (
    "time"
    "timer"
)

type PrintTask struct {
    ID uint
}

func (pt *PrintTask) Do() {
    println("print", pt.ID)
}

type WriteTask struct {
    ID uint
}

func (wt *WriteTask) Do() {
    println("write", wt.ID)
}

func main() {
    t := timer.NewTimer()
    t3 := &PrintTask{5}
    t2 := &WriteTask{3}
    t1 := &PrintTask{1}
    t.AddTask(t3, 5)
    t.AddTask(t2, 3)
    t.AddTask(t1, 1)
    time.Sleep(7 * time.Second)
    t.Close()
}

About

timer task or object

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages