Documentation ¶
Overview ¶
Package scheduler provides a task scheduler which dipatches tasks at the specified time for each task.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Scheduler ¶
type Scheduler struct { C chan *Task // contains filtered or unexported fields }
Scheduler sends a scheduled task with the channel C at the specified time. The order of tasks at the same time is not specified and may not be the same order as calls of Schedule() for those tasks.
func NewScheduler ¶
NewScheduler creates a scheduler. Pass a context created with context.WithCancel() and call cancel() (the cancel function is also returned from context.WithCancel()) to stop the created scheduler.
func (*Scheduler) Cancel ¶
Cancel the task. It returns true if the task is canceled, or false if the task has been already dispatched.
func (*Scheduler) CancelEarliest ¶
Cancel the earliest task. It returns the canceled task, or nil if the queue was empty.
type Task ¶
type Task struct { Data interface{} // contains filtered or unexported fields }
Task represents a scheduled task. It has the time and user data. You may modify the user data after calling Scheduler.Schedule().
type TaskQueue ¶
type TaskQueue struct {
// contains filtered or unexported fields
}
TaskQueue represents a queue for tasks. Tasks are sorted by time.
func (*TaskQueue) Peek ¶
Peek returns the earliest task without removing it from the TaskQueue. Returns nil if the TaskQueue is empty.
func (*TaskQueue) Pop ¶
Pop the earliest task from the TaskQueue. Returns nil if the TaskQueue is empty.