forked from Mirrors/bubbletea
Built-in subscriptions are clearer without the extra type definition
This commit is contained in:
parent
b6eeef2127
commit
767f4bec2d
|
@ -4,16 +4,10 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// NewEveryMsg is used by Every to create a new message. It contains the time
|
||||
// at which the timer finished.
|
||||
type NewEveryMsg func(time.Time) Msg
|
||||
|
||||
// Every is a subscription that ticks with the system clock at the given
|
||||
// duration, similar to cron. It's particularly useful if you have several
|
||||
// subscriptions that need to run in sync.
|
||||
//
|
||||
// TODO: make it cancelable.
|
||||
func Every(duration time.Duration, newMsg NewEveryMsg) Sub {
|
||||
func Every(duration time.Duration, newMsg func(time.Time) Msg) Sub {
|
||||
return func() Msg {
|
||||
n := time.Now()
|
||||
d := n.Truncate(duration).Add(duration).Sub(n)
|
||||
|
@ -27,9 +21,7 @@ func Every(duration time.Duration, newMsg NewEveryMsg) Sub {
|
|||
|
||||
// Tick is a subscription that at an interval independent of the system clock
|
||||
// at the given duration. That is, it begins precisely when invoked.
|
||||
//
|
||||
// TODO: make it cancelable.
|
||||
func Tick(d time.Duration, newMsg NewEveryMsg) Sub {
|
||||
func Tick(d time.Duration, newMsg func(time.Time) Msg) Sub {
|
||||
return func() Msg {
|
||||
t := time.NewTimer(d)
|
||||
select {
|
||||
|
|
Loading…
Reference in New Issue