backgroundtasks

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package backgroundtasks runs Go now and then, with the app closed.

nimbus native plugin add background-tasks

func init() {
	backgroundtasks.Handle("sync", func(ctx context.Context) error {
		return uploadOrders(ctx)
	})
}

backgroundtasks.Schedule(ctx, "sync", time.Hour)

The system picks the moment, from how the phone is used, so treat the interval as a hint. Android runs a task at most every 15 minutes, and iOS far less often, and never after the person force-quits the app. A task has about 25 seconds. There is no screen: ui code doesn't run.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cancel

func Cancel(ctx context.Context, name string) error

Cancel stops a task.

func Handle

func Handle(name string, f func(context.Context) error)

Handle says what a task does. Call it from init, so that it's there when the system starts the app with no screen.

func Once

func Once(ctx context.Context, name string, after time.Duration) error

Once asks for a task to run one time, no sooner than after: to retry an upload later, say.

func Schedule

func Schedule(ctx context.Context, name string, every time.Duration) error

Schedule asks for a task to run about every so often. Scheduling it again replaces the interval.

Types

This section is empty.

Jump to

Keyboard shortcuts

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