Start adding DSL
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
package asana
|
package asanaclient
|
||||||
|
|
||||||
import "bytes"
|
import "bytes"
|
||||||
import "encoding/json"
|
import "encoding/json"
|
||||||
59
asanarules/rules.go
Normal file
59
asanarules/rules.go
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package asanarules
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type periodic struct {
|
||||||
|
duration time.Duration
|
||||||
|
done chan bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var periodics = []*periodic{}
|
||||||
|
|
||||||
|
func Every(d time.Duration) *periodic {
|
||||||
|
ret := &periodic{
|
||||||
|
duration: d,
|
||||||
|
done: make(chan bool),
|
||||||
|
}
|
||||||
|
|
||||||
|
periodics = append(periodics, ret)
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func Loop() {
|
||||||
|
for _, periodic := range periodics {
|
||||||
|
periodic.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, periodic := range periodics {
|
||||||
|
periodic.wait()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *periodic) MyTasks() *periodic {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *periodic) start() {
|
||||||
|
go p.loop()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *periodic) wait() {
|
||||||
|
<-p.done
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *periodic) loop() {
|
||||||
|
ticker := time.NewTicker(p.duration)
|
||||||
|
|
||||||
|
for {
|
||||||
|
<-ticker.C
|
||||||
|
p.exec()
|
||||||
|
}
|
||||||
|
|
||||||
|
close(p.done)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *periodic) exec() {
|
||||||
|
fmt.Printf("exec\n")
|
||||||
|
}
|
||||||
13
main.go
13
main.go
@@ -1,10 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
// import "fmt"
|
||||||
|
import "time"
|
||||||
|
|
||||||
import "github.com/firestuff/asana-rules/asana"
|
import . "github.com/firestuff/asana-rules/asanarules"
|
||||||
|
|
||||||
|
// import "github.com/firestuff/asana-rules/asanaclient"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
Every(5 * time.Second).
|
||||||
|
MyTasks()
|
||||||
|
|
||||||
|
Loop()
|
||||||
|
/*
|
||||||
a := asana.NewClientFromEnv()
|
a := asana.NewClientFromEnv()
|
||||||
|
|
||||||
me, err := a.GetMe()
|
me, err := a.GetMe()
|
||||||
@@ -58,4 +66,5 @@ func main() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user