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 ¶
var ErrUnknown = errors.New("background: no task registered with this name")
ErrUnknown is returned by Schedule for a task without Register.
Functions ¶
Types ¶
type Func ¶
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.