task

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package task implements background task that satisfies task.Tasker interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Task

type Task struct {
	// Name of the task, for logging purposes
	Name string
	// contains filtered or unexported fields
}

Task is a background task. It can be started and stopped. Before task is able to run, it must have Task.initialized=true and Task.loop set with Task.SetLoop(). Task recovers from panics in Task.loop. These panics are logged with stacktrace and then application exits.

func (*Task) IsRunning

func (t *Task) IsRunning() bool

IsRunning returns whether task is running or not

func (*Task) SetLoop

func (t *Task) SetLoop(loop func())

func (*Task) Start

func (t *Task) Start() error

Start starts task. If task is already running, or task loop is missing, task returns error

func (*Task) Stop

func (t *Task) Stop() error

Stop stops task. If task is not running, return error

func (*Task) StopChan

func (t *Task) StopChan() chan bool

StopChan returns stop channel that receives value when task stop is called

type Tasker

type Tasker interface {
	Start() error
	Stop() error
}

Tasker can be run on background

Jump to

Keyboard shortcuts

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