Created
December 10, 2023 19:11
-
-
Save hallazzang/d65e6b4a3f265b639995733b6f943b0a to your computer and use it in GitHub Desktop.
Go ticker which runs immediately after creating
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func NewTicker(d time.Duration) *time.Ticker { | |
ticker := time.NewTicker(d) | |
oc := ticker.C | |
nc := make(chan time.Time, 1) | |
go func() { | |
nc <- time.Now() | |
for t := range oc { | |
nc <- t | |
} | |
}() | |
ticker.C = nc | |
return ticker | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment