Skip to content
Myr

Built-in subscriptions are clearer without the extra type definition

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Christian Rocha · committed by Christian Rocha · parent b6eeef2 · Browse files · 1 file+2 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+2 added−10 removed

  • other:+2 added−10 removed

1 file+2 added−10 removed

modified:subscriptions.go+2 added-10 removed
2 unmodified lines
3import (4 "time"5)67// NewEveryMsg is used by Every to create a new message. It contains the time8// at which the timer finished.9type NewEveryMsg func(time.Time) Msg107// Every is a subscription that ticks with the system clock at the given8// duration, similar to cron. It's particularly useful if you have several9// subscriptions that need to run in sync.14//15// TODO: make it cancelable.16func Every(duration time.Duration, newMsg NewEveryMsg) Sub {10func Every(duration time.Duration, newMsg func(time.Time) Msg) Sub {11 return func() Msg {12 n := time.Now()13 d := n.Truncate(duration).Add(duration).Sub(n)14 t := time.NewTimer(d)
5 unmodified lines
20}2122// Tick is a subscription that at an interval independent of the system clock23// at the given duration. That is, it begins precisely when invoked.30//31// TODO: make it cancelable.32func Tick(d time.Duration, newMsg NewEveryMsg) Sub {24func Tick(d time.Duration, newMsg func(time.Time) Msg) Sub {25 return func() Msg {26 t := time.NewTimer(d)27 select {28 case now := <-t.C:
4 unmodified lines