aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-04-09 11:44:34 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-04-09 11:44:34 +0200
commit195c098360cf67e4918b069b905c89d6d510fac4 (patch)
treecf04eb205cc04d8dc9725c2b86754829f6e9d787 /main.go
parent0167d97b3e4f40a58f25eb39e4034d08dbca51c4 (diff)
wip
Diffstat (limited to 'main.go')
-rw-r--r--main.go37
1 files changed, 18 insertions, 19 deletions
diff --git a/main.go b/main.go
index 3cbe411..2cc50c4 100644
--- a/main.go
+++ b/main.go
@@ -3,7 +3,6 @@ package main
import (
"context"
"flag"
- "fmt"
"log"
"os"
"os/signal"
@@ -17,10 +16,10 @@ type Opt struct {
Day time.Duration
Runs int
run int
- disp chan display
+ do chan do
}
-type display struct {
+type do struct {
s string
d time.Duration
}
@@ -28,13 +27,13 @@ type display struct {
type stateFn func(context.Context) stateFn
func (o *Opt) doWork(ctx context.Context) stateFn {
- t := time.NewTimer(o.Work)
- defer t.Stop()
- o.disp <- display{"work", o.Work}
+ timer := time.NewTimer(o.Work)
+ defer timer.Stop()
+ o.do <- do{"work", o.Work}
select {
case <-ctx.Done():
return nil
- case <-t.C:
+ case <-timer.C:
return o.doBreak
}
}
@@ -47,31 +46,31 @@ func (o *Opt) doBreak(_ context.Context) stateFn {
}
func (o *Opt) shortBreak(ctx context.Context) stateFn {
- t := time.NewTimer(o.Short)
- defer t.Stop()
- o.disp <- display{"short", o.Short}
+ timer := time.NewTimer(o.Short)
+ defer timer.Stop()
+ o.do <- do{"short", o.Short}
select {
case <-ctx.Done():
return nil
- case <-t.C:
+ case <-timer.C:
return o.doWork
}
}
func (o *Opt) longBreak(ctx context.Context) stateFn {
- t := time.NewTimer(o.Long)
- defer t.Stop()
- o.disp <- display{"long", o.Long}
+ timer := time.NewTimer(o.Long)
+ defer timer.Stop()
+ o.do <- do{"long", o.Long}
select {
case <-ctx.Done():
return nil
- case <-t.C:
+ case <-timer.C:
return o.doWork
}
}
-func notifier(ctx context.Context) chan display {
- c := make(chan display)
+func notifier(ctx context.Context) chan do {
+ c := make(chan do)
go func() {
defer close(c)
for v := range c {
@@ -79,7 +78,7 @@ func notifier(ctx context.Context) chan display {
case <-ctx.Done():
return
default:
- fmt.Println("Do", v.s, v.d)
+ count(ctx, v.s, v.d)
}
}
}()
@@ -100,7 +99,7 @@ func (o *Opt) pomodoro() {
ctx, cancel := context.WithTimeout(context.Background(), o.Day)
defer cancel()
atInterrupt(cancel)
- o.disp = notifier(ctx)
+ o.do = notifier(ctx)
for s := o.doWork; s != nil; s = s(ctx) {
}
}