schedule

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package schedule implements in-process reminders: after for relative one-shot delays, at for absolute one-shot times, and every for fixed intervals of at least five minutes. Registration, delivery, and cancellation stay within the owning session.

Index

Constants

View Source
const MinEveryInterval = 5 * time.Minute

MinEveryInterval is the minimum periodic interval: five minutes.

Variables

View Source
var ErrEmptyPrompt = errors.New("schedule: empty prompt")

ErrEmptyPrompt indicates empty reminder content.

View Source
var ErrIntervalTooShort = errors.New("schedule: every interval below minimum")

ErrIntervalTooShort indicates an interval below the minimum.

View Source
var ErrNotFuture = errors.New("schedule: target is not in the future")

ErrNotFuture indicates a target time that is not in the future.

Functions

This section is empty.

Types

type Dispatch

type Dispatch struct {
	ID     string
	Prompt string
}

Dispatch describes a due reminder notification.

type Entry

type Entry struct {
	ID       string
	Kind     Kind
	Prompt   string
	NextAt   time.Time
	Interval time.Duration // Used only for every.
}

Entry represents an active reminder.

type Kind

type Kind string

Kind identifies a scheduling rule.

const (
	KindAfter Kind = "after" // Relative one-shot delay.
	KindAt    Kind = "at"    // Absolute one-shot time.
	KindEvery Kind = "every" // Fixed interval.
)

type Scheduler

type Scheduler struct {
	// contains filtered or unexported fields
}

Scheduler is a concurrency-safe in-process scheduler.

func New

func New() *Scheduler

New creates a scheduler that sends dispatches to its output channel.

func (*Scheduler) After

func (s *Scheduler) After(id, prompt string, delay time.Duration) error

After registers a relative one-shot reminder.

func (*Scheduler) At

func (s *Scheduler) At(id, prompt string, at time.Time) error

At registers an absolute one-shot reminder.

func (*Scheduler) Cancel

func (s *Scheduler) Cancel(id string) bool

Cancel cancels a reminder, returning false if absent.

func (*Scheduler) Every

func (s *Scheduler) Every(id, prompt string, interval time.Duration) error

Every registers a fixed-interval reminder.

func (*Scheduler) List

func (s *Scheduler) List() []Entry

List returns a snapshot of active reminders.

func (*Scheduler) Out

func (s *Scheduler) Out() <-chan Dispatch

Out returns the due-notification channel.

func (*Scheduler) SetNow

func (s *Scheduler) SetNow(f func() time.Time)

SetNow injects a clock for testing.

func (*Scheduler) Shutdown

func (s *Scheduler) Shutdown()

Shutdown stops all timers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL