asynctask

package
v5.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 4 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncTask

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

AsyncTask is a struct that wraps tasks that should run periodically and can be remotely stopped & started, as well as making it's status (running/stopped) available.

func NewAsyncTask

func NewAsyncTask(
	name string,
	task func(l logging.LoggerInterface) error,
	period int,
	onInit func(l logging.LoggerInterface) error,
	onStop func(l logging.LoggerInterface),
	logger logging.LoggerInterface,
) *AsyncTask

NewAsyncTask creates a new task and returns a pointer to it

func (*AsyncTask) IsRunning

func (t *AsyncTask) IsRunning() bool

IsRunning returns true if the task is currently running

func (*AsyncTask) Start

func (t *AsyncTask) Start()

Start initiates the task. It wraps the execution in a closure guarded by a call to recover() in order to prevent the main application from crashin if something goes wrong while the sdk interacts with the backend.

func (*AsyncTask) Stop

func (t *AsyncTask) Stop(blocking bool) error

Stop executes onStop hook if any, blocks until its done (if blocking = true) and prevents future executions of the task.

func (*AsyncTask) WakeUp

func (t *AsyncTask) WakeUp() error

WakeUp interrupts the task's sleep period and resumes execution

Jump to

Keyboard shortcuts

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