schedgroup

package
v0.0.0-...-04966db Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package schedgroup provides a goroutine worker pool which schedules tasks to be performed at or after a specified time.

Special thanks to Egon Elbre from #performance on Gophers Slack for two prototypes (https://play.golang.org/p/YyeSWuDil-b, https://play.golang.org/p/4iYBO6Cgj8m) of this idea, based on Go's container/heap package. Egon's prototypes heavily influenced the final design of this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

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

A Group is a goroutine worker pool which schedules tasks to be performed after a specified time. A Group must be created with the New constructor.

func New

func New(ctx context.Context) *Group

New creates a new Group which will use ctx for cancelation. If cancelation is not a concern, use context.Background().

func (*Group) Delay

func (g *Group) Delay(delay time.Duration, fn func())

Delay schedules a function to run at or after the specified delay. Delay is a convenience wrapper for Schedule which adds delay to the current time. Specifying a negative delay will cause the task to be scheduled immediately.

If Delay is called after a call to Wait, Delay will panic.

func (*Group) Schedule

func (g *Group) Schedule(when time.Time, fn func())

Schedule schedules a function to run at or after the specified time. Specifying a past time will cause the task to be scheduled immediately.

func (*Group) Wait

func (g *Group) Wait() error

Wait waits for the completion of all scheduled tasks, or for cancelation of the context passed to New.

Jump to

Keyboard shortcuts

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