background

package
v1.0.31-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package background runs the app's work while it isn't on screen: a sync every hour or so, a cleanup at night while charging. The system decides when, within the app's constraints, and starts the app's process for it when it isn't running.

  • iOS: BGTaskScheduler. A task is an app refresh (about 30 seconds) or, when Long, a processing task (minutes, usually at night while charging). Each task's name must be listed in giode.toml's app.background_tasks, which permits its identifier.
  • Android: JobScheduler, with network and charging constraints; a job gets up to about ten minutes. Periodic jobs run at most every 15 minutes and survive reboots.
  • Computers: the task runs on a timer while the app runs.

Register each task's function early, in main before App.Run: the system can start the app's process just to run one.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknown = errors.New("background: no task registered with this name")

ErrUnknown is returned by Schedule for a task without Register.

Functions

func Cancel

func Cancel(name string) error

Cancel removes the task's schedule.

func Register

func Register(name string, f Func)

Register sets the work of the task with the given name.

func Schedule

func Schedule(name string, o Options) error

Schedule asks the system to run the task, replacing an earlier schedule of it.

Types

type Func

type Func func(ctx context.Context) error

Func is a task's work. ctx is canceled when the system ends the task's time; return soon after. An error asks the system to try again later (Android) or reports a failed run (iOS).

type Options

type Options struct {
	// Interval runs the task again about this often; zero runs it once.
	// Android's minimum is 15 minutes; iOS treats it as the earliest
	// next run.
	Interval time.Duration
	// Delay is the earliest the first run starts.
	Delay time.Duration
	// Network runs the task only with a network connection.
	Network bool
	// Charging runs the task only while the device charges.
	Charging bool
	// Long asks for minutes rather than seconds: an iOS processing task,
	// which the system usually runs at night. Android jobs get minutes
	// either way.
	Long bool
}

Options say when a task may run.

Jump to

Keyboard shortcuts

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