Schedule
⏰ Easily schedule non-blocking tasks in Go. Supports durations, specific times and intervals.
Install / Use
/learn @atomicgo/ScheduleREADME
<p align="center"> <strong><a href="https://pkg.go.dev/atomicgo.dev/schedule#section-documentation" target="_blank">Documentation</a></strong> | <strong><a href="https://github.com/atomicgo/atomicgo/blob/main/CONTRIBUTING.md" target="_blank">Contributing</a></strong> | <strong><a href="https://github.com/atomicgo/atomicgo/blob/main/CODE_OF_CONDUCT.md" target="_blank">Code of Conduct</a></strong> </p>
<p align="center"> <img src="https://raw.githubusercontent.com/atomicgo/atomicgo/main/assets/header.png" alt="AtomicGo"> </p> <p align="center"> <table> <tbody> </tbody> </table> </p> <h3 align="center"><pre>go get atomicgo.dev/schedule</pre></h3> <p align="center"> <table> <tbody> </tbody> </table> </p> <!-- gomarkdoc:embed:start --> <!-- Code generated by gomarkdoc. DO NOT EDIT -->
schedule
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
- func After(duration time.Duration, task func()) *Task
- func At(t time.Time, task func()) *Task
- func Every(interval time.Duration, task func() bool) *Task
- func (s *Task) ExecutesIn() time.Duration
- func (s *Task) IsActive() bool
- func (s *Task) NextExecutionTime() time.Time
- func (s *Task) StartedAt() time.Time
- func (s *Task) Stop()
- func (s *Task) Wait()
<a name="Task"></a>
type Task
Task holds information about the running task and can be used to stop running tasks.
type Task struct {
// contains filtered or unexported fields
}
<a name="After"></a>
func After
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.
<details><summary>Example</summary> <p>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()
}
</p>
</details>
<a name="At"></a>
func At
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.
<details><summary>Example</summary> <p>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()
}
</p>
</details>
<a name="Every"></a>
func Every
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.
<details><summary>Example</summary> <p>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()
}
</p>
</details>
<a name="Task.ExecutesIn"></a>
func (*Task) ExecutesIn
func (s *Task) ExecutesIn() time.Duration
ExecutesIn returns the duration until the next execution.
<a name="Task.IsActive"></a>
func (*Task) IsActive
func (s *Task) IsActive() bool
IsActive returns true if the scheduler is active.
<a name="Task.NextExecutionTime"></a>
func (*Task) NextExecutionTime
func (s *Task) NextExecutionTime() time.Time
NextExecutionTime returns the time when the next execution will happen.
<a name="Task.StartedAt"></a>
func (*Task) StartedAt
func (s *Task) StartedAt() time.Time
StartedAt returns the time when the scheduler was started.
<a name="Task.Stop"></a>
func (*Task) Stop
func (s *Task) Stop()
Stop stops the scheduler.
<a name="Task.Wait"></a>
func (*Task) Wait
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
<!-- gomarkdoc:embed:end -->AtomicGo.dev · with ❤️ by @MarvinJWendt | MarvinJWendt.com
Related Skills
xurl
345.4kA CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
kubeshark
11.9kCluster-wide network observability for Kubernetes. Captures L4 packets, L7 API calls, and decrypted TLS traffic using eBPF, with full Kubernetes context. Available to AI agents via MCP and human operators via dashboard.
gin-vue-admin
24.5k🚀Vite+Vue3+Gin拥有AI辅助的基础开发平台,企业级业务AI+开发解决方案,内置mcp辅助服务,内置skills管理,支持TS和JS混用。它集成了JWT鉴权、权限管理、动态路由、显隐可控组件、分页封装、多点登录拦截、资源权限、上传下载、代码生成器、表单生成器和可配置的导入导出等开发必备功能。
mcp-gateway
40Model Context Protocol (MCP) Gateway & Registry - Central hub for managing tools, resources, and prompts for MCP-compatible LLMs. Translates REST APIs into MCP, builds virtual MCP servers with security and observability, and bridges multiple transports (stdio, SSE, streamable HTTP).
