scheduler

package module
v0.0.0-...-87a28ea Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2016 License: MIT Imports: 4 Imported by: 0

README

scheduler

A simple time scheduler library for Go. See https://godoc.org/github.com/hnakamur/scheduler for the API document.

License

MIT

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

func NewScheduler(ctx context.Context) *Scheduler

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

func (s *Scheduler) Cancel(task *Task) bool

Cancel the task. It returns true if the task is canceled, or false if the task has been already dispatched.

func (*Scheduler) CancelEarliest

func (s *Scheduler) CancelEarliest() *Task

Cancel the earliest task. It returns the canceled task, or nil if the queue was empty.

func (*Scheduler) Schedule

func (s *Scheduler) Schedule(t time.Time, data interface{}) *Task

Schedule a task with the time to dispatch and the user data. It returns the task object which you can use for canceling this task.

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().

func (*Task) Time

func (t *Task) Time() time.Time

Time returns the time when the task will be dispatched.

type TaskQueue

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

TaskQueue represents a queue for tasks. Tasks are sorted by time.

func NewTaskQueue

func NewTaskQueue() *TaskQueue

NewTaskQueue creates a TaskQueue.

func (*TaskQueue) Len

func (q *TaskQueue) Len() int

Len returns the length of the TaskQueue.

func (*TaskQueue) Peek

func (q *TaskQueue) Peek() *Task

Peek returns the earliest task without removing it from the TaskQueue. Returns nil if the TaskQueue is empty.

func (*TaskQueue) Pop

func (q *TaskQueue) Pop() *Task

Pop the earliest task from the TaskQueue. Returns nil if the TaskQueue is empty.

func (*TaskQueue) Push

func (q *TaskQueue) Push(t time.Time, data interface{}) *Task

Push a task with the time to dispatch and the user data. It returns the task object which you can use for removing this task.

func (*TaskQueue) Remove

func (q *TaskQueue) Remove(task *Task) bool

Remove a task from the TaskQueue. Returns true if the task was removed, or false if the task was already removed.

Jump to

Keyboard shortcuts

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