schedule

package
v0.0.0-...-bcea9b7 Latest Latest
Warning

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

Go to latest
Published: May 10, 2021 License: MIT Imports: 5 Imported by: 0

README

Usage

FIFO scheduler: schedule jobs that will be ran in FIFO order sequentially.

alt text

Example

package main 

import (
	"github.com/donutloop/toolkit/schedule"
	"log"
)

func main() {
        // creation of jobs

		s := schedule.NewFIFOScheduler()
    	defer s.Stop()
    
    	for _, job := range jobs {
    		s.Schedule(job)
    	}
    
    	s.WaitFinish(100)
}

Documentation

Overview

Example
package main

import (
	"context"
	"fmt"

	"github.com/donutloop/toolkit/schedule"
)

func main() {
	s := schedule.NewFIFOScheduler()
	defer s.Stop()

	job := func(ctx context.Context) {
		fmt.Println("create db entry")
	}

	if err := s.Schedule(job); err != nil {
		fmt.Printf("error: (%v) \n", err)
	}

	s.WaitFinish(1)

}
Output:

create db entry

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrStoppedScheduler error = errors.New("schedule: schedule to stopped scheduler")

Functions

This section is empty.

Types

type DebugStack

type DebugStack []byte

type Fifo

type Fifo struct {
	PanicHandler func(DebugStack)
	// contains filtered or unexported fields
}

func NewFIFOScheduler

func NewFIFOScheduler() *Fifo

NewFIFOScheduler returns a Scheduler that schedules jobs in FIFO order sequentially.

func (*Fifo) Finished

func (f *Fifo) Finished() int

func (*Fifo) Pending

func (f *Fifo) Pending() int

func (*Fifo) Schedule

func (f *Fifo) Schedule(j Job) error

Schedule schedules a job that will be ran in FIFO order sequentially.

func (*Fifo) Scheduled

func (f *Fifo) Scheduled() int

func (*Fifo) Stop

func (f *Fifo) Stop()

Stop stops the scheduler and cancels all pending jobs.

func (*Fifo) WaitFinish

func (f *Fifo) WaitFinish(n int)

type Job

type Job func(context.Context)

Jump to

Keyboard shortcuts

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