actions

package
v0.0.0-...-883f3e4 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: MPL-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action interface {
	// Run runs the action, possibly to completion.
	// The parameter says for how long the action is allowed to run.
	//
	// The returned status says if the action has completed.
	// It also says how much time is left after it has run.
	Run(atMost time.Duration) Status
}

An Action is a process stretched out in time.

func Interrupt

func Interrupt() Action

Interrupt returns an action that immediately interrupts.

func NoAction

func NoAction() Action

NoAction returns an action that completes instantly.

Running the returned action has no side-effects.

func Sequence

func Sequence(steps ...Action) Action

Sequence creates an action that runs several steps one after another.

func Wait

func Wait(waitTime time.Duration) Action

Wait returns an action that lasts waitTime but does nothing.

type Countdown

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

A Countdown tracks progress towards reaching a numerical goal. The zero value is a completed countdown with a goal of 0.

func (*Countdown) Action

func (c *Countdown) Action(lasting time.Duration) Action

Action creates an action that makes the countdown progress run. The countdown completes when the action does.

func (*Countdown) CountDown

func (c *Countdown) CountDown(atMost int) (leftOver int)

CountDown tracks progress being made towards a countdown. The countdown gets closer to completion with bigger arguments.

func (Countdown) Progress

func (c Countdown) Progress() float64

Progress says how far along the countdown is. The value ranges from 0 (not started) to 1 (completed).

func (*Countdown) ResetTarget

func (c *Countdown) ResetTarget(needed int)

ResetTarget sets a new target value and resets all progress made.

type Status

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

An Status says whether an action completed. It also says how much time is left after running it.

func Done

func Done(timeLeft time.Duration) Status

Done creates an action status indicating that an action has completed.

The timeLeft should be the time the action did not use up. As a special case, there will be no time left when the argument is negative.

func Interrupted

func Interrupted(timeLeft time.Duration) Status

Interrupted creates an action status saying that the action was interrupted.

The timeLeft should be the time the action did not use up. As a special case, there will be no time left when the argument is negative.

func Paused

func Paused() Status

Paused creates an action status indicating that an action needs more time to complete.

func (Status) Done

func (status Status) Done() bool

Done says whether the action has completed.

func (Status) HasTimeLeft

func (status Status) HasTimeLeft() bool

HasTimeLeft says whether there is time left after running an action.

func (Status) Interrupted

func (status Status) Interrupted() bool

Interrupted says whether the action was interrupted.

func (Status) TimeLeft

func (status Status) TimeLeft() time.Duration

TimeLeft returns the time still left after running the action.

Jump to

Keyboard shortcuts

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