https://github.com/atomicgo/schedule
⏰ Easily schedule non-blocking tasks in Go. Supports durations, specific times and intervals.
https://github.com/atomicgo/schedule
atomicgo go golang golang-library hacktoberfest schedule scheduler ticker time timer
Last synced: about 1 year ago
JSON representation
⏰ Easily schedule non-blocking tasks in Go. Supports durations, specific times and intervals.
- Host: GitHub
- URL: https://github.com/atomicgo/schedule
- Owner: atomicgo
- License: mit
- Created: 2022-10-04T14:31:31.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-02-27T12:18:39.000Z (over 1 year ago)
- Last Synced: 2025-02-27T17:20:48.578Z (over 1 year ago)
- Topics: atomicgo, go, golang, golang-library, hacktoberfest, schedule, scheduler, ticker, time, timer
- Language: Go
- Homepage: https://atomicgo.dev
- Size: 45.9 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
AtomicGo | schedule

---
Documentation
|
Contributing
|
Code of Conduct
---
go get atomicgo.dev/schedule
# schedule
```go
import "atomicgo.dev/schedule"
```
Package schedule provides a simple scheduler for Go.
It can run a function at a given time, in a given duration, or repeatedly at a given interval.
## Index
- [type Task](<#Task>)
- [func After\(duration time.Duration, task func\(\)\) \*Task](<#After>)
- [func At\(t time.Time, task func\(\)\) \*Task](<#At>)
- [func Every\(interval time.Duration, task func\(\) bool\) \*Task](<#Every>)
- [func \(s \*Task\) ExecutesIn\(\) time.Duration](<#Task.ExecutesIn>)
- [func \(s \*Task\) IsActive\(\) bool](<#Task.IsActive>)
- [func \(s \*Task\) NextExecutionTime\(\) time.Time](<#Task.NextExecutionTime>)
- [func \(s \*Task\) StartedAt\(\) time.Time](<#Task.StartedAt>)
- [func \(s \*Task\) Stop\(\)](<#Task.Stop>)
- [func \(s \*Task\) Wait\(\)](<#Task.Wait>)
Task holds information about the running task and can be used to stop running tasks.
```go
type Task struct {
// contains filtered or unexported fields
}
```
```go
func After(duration time.Duration, task func()) *Task
```
After executes the task after the given duration. The function is non\-blocking. If you want to wait for the task to be executed, use the Task.Wait method.
Example
```go
package main
import (
"fmt"
"time"
"atomicgo.dev/schedule"
)
func main() {
task := schedule.After(5*time.Second, func() {
fmt.Println("5 seconds are over!")
})
fmt.Println("Some stuff happening...")
task.Wait()
}
```
```go
func At(t time.Time, task func()) *Task
```
At executes the task at the given time. The function is non\-blocking. If you want to wait for the task to be executed, use the Task.Wait method.
Example
```go
package main
import (
"fmt"
"time"
"atomicgo.dev/schedule"
)
func main() {
task := schedule.At(time.Now().Add(5*time.Second), func() {
fmt.Println("5 seconds are over!")
})
fmt.Println("Some stuff happening...")
task.Wait()
}
```
```go
func Every(interval time.Duration, task func() bool) *Task
```
Every executes the task in the given interval, as long as the task function returns true. The function is non\-blocking. If you want to wait for the task to be executed, use the Task.Wait method.
Example
```go
package main
import (
"fmt"
"time"
"atomicgo.dev/schedule"
)
func main() {
task := schedule.Every(time.Second, func() bool {
fmt.Println("1 second is over!")
return true // return false to stop the task
})
fmt.Println("Some stuff happening...")
time.Sleep(10 * time.Second)
task.Stop()
}
```
### func \(\*Task\) [ExecutesIn]()
```go
func (s *Task) ExecutesIn() time.Duration
```
ExecutesIn returns the duration until the next execution.
### func \(\*Task\) [IsActive]()
```go
func (s *Task) IsActive() bool
```
IsActive returns true if the scheduler is active.
### func \(\*Task\) [NextExecutionTime]()
```go
func (s *Task) NextExecutionTime() time.Time
```
NextExecutionTime returns the time when the next execution will happen.
### func \(\*Task\) [StartedAt]()
```go
func (s *Task) StartedAt() time.Time
```
StartedAt returns the time when the scheduler was started.
```go
func (s *Task) Stop()
```
Stop stops the scheduler.
```go
func (s *Task) Wait()
```
Wait blocks until the scheduler is stopped. After and At will stop automatically after the task is executed.
Generated by [gomarkdoc]()
---
> [AtomicGo.dev](https://atomicgo.dev) ·
> with ❤️ by [@MarvinJWendt](https://github.com/MarvinJWendt) |
> [MarvinJWendt.com](https://marvinjwendt.com)