new playAnimationUntil that stops animation when notify channel receives message
build lightwatch / build (push) Has started running Details

main
Nathan Wagner 10 months ago
parent 6e27fc641b
commit 3d3b3fbf7b

@ -64,7 +64,6 @@ func (tk *ToolKit) PlayAnimation(a Animation) error {
return err
}
}
if err == io.EOF {
return nil
}
@ -72,6 +71,35 @@ func (tk *ToolKit) PlayAnimation(a Animation) error {
return err
}
func (tk *ToolKit) PlayAnimationUntil(a Animation, notify <-chan bool) error {
var err error
var i image.Image
var n <-chan time.Time
var outerError error
for outerError == nil {
select {
case <-notify:
return nil
default:
i, n, err = a.Next()
if err != nil {
outerError = err
break
}
if err := tk.PlayImageUntil(i, n); err != nil {
return err
}
}
}
if outerError == io.EOF {
return nil
}
return err
}
// PlayImageUntil draws the given image until is notified to stop
func (tk *ToolKit) PlayImageUntil(i image.Image, notify <-chan time.Time) error {
defer func() {

Loading…
Cancel
Save