aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-04-07 09:27:40 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-04-07 09:27:40 +0200
commit0167d97b3e4f40a58f25eb39e4034d08dbca51c4 (patch)
treecf3575cfad7d7ad2d9d073b9dd83a05f24c31ea9
parent7109fe10f62236b0bbabbda6325143f4855833c4 (diff)
...
-rw-r--r--main.go23
1 files changed, 12 insertions, 11 deletions
diff --git a/main.go b/main.go
index 24cfb3c..3cbe411 100644
--- a/main.go
+++ b/main.go
@@ -17,6 +17,7 @@ type Opt struct {
Day time.Duration
Runs int
run int
+ disp chan display
}
type display struct {
@@ -24,12 +25,12 @@ type display struct {
d time.Duration
}
-type stateFn func(context.Context, chan display) stateFn
+type stateFn func(context.Context) stateFn
-func (o *Opt) doWork(ctx context.Context, c chan display) stateFn {
+func (o *Opt) doWork(ctx context.Context) stateFn {
t := time.NewTimer(o.Work)
defer t.Stop()
- c <- display{"Work", o.Work}
+ o.disp <- display{"work", o.Work}
select {
case <-ctx.Done():
return nil
@@ -38,17 +39,17 @@ func (o *Opt) doWork(ctx context.Context, c chan display) stateFn {
}
}
-func (o *Opt) doBreak(_ context.Context, _ chan display) stateFn {
+func (o *Opt) doBreak(_ context.Context) stateFn {
if o.run++; o.run%o.Runs == 0 {
return o.longBreak
}
return o.shortBreak
}
-func (o *Opt) shortBreak(ctx context.Context, c chan display) stateFn {
+func (o *Opt) shortBreak(ctx context.Context) stateFn {
t := time.NewTimer(o.Short)
defer t.Stop()
- c <- display{"Short", o.Short}
+ o.disp <- display{"short", o.Short}
select {
case <-ctx.Done():
return nil
@@ -57,10 +58,10 @@ func (o *Opt) shortBreak(ctx context.Context, c chan display) stateFn {
}
}
-func (o *Opt) longBreak(ctx context.Context, c chan display) stateFn {
+func (o *Opt) longBreak(ctx context.Context) stateFn {
t := time.NewTimer(o.Long)
defer t.Stop()
- c <- display{"Long", o.Long}
+ o.disp <- display{"long", o.Long}
select {
case <-ctx.Done():
return nil
@@ -78,7 +79,7 @@ func notifier(ctx context.Context) chan display {
case <-ctx.Done():
return
default:
- fmt.Println(v.s, v.d)
+ fmt.Println("Do", v.s, v.d)
}
}
}()
@@ -99,8 +100,8 @@ func (o *Opt) pomodoro() {
ctx, cancel := context.WithTimeout(context.Background(), o.Day)
defer cancel()
atInterrupt(cancel)
- c := notifier(ctx)
- for s := o.doWork; s != nil; s = s(ctx, c) {
+ o.disp = notifier(ctx)
+ for s := o.doWork; s != nil; s = s(ctx) {
}
}