Skip to content

PluginJobs

Runs slow work in the background, so that it does not delay a change. The app cancels a job when the plugin is turned off. Using it requires the jobs permission.

Process many rows without freezing the app

await ctx.jobs.run(async signal => {
for (const id of ids) {
signal.throwIfAborted(); // stops the job when the plugin was turned off
await processRow(id);
await ctx.jobs.yield(); // lets the app do other work between two rows
}
});
run<T>(job): Promise<T>;

Runs a job in the background.

Type Parameter Description
T the type of the value that the job returns
Parameter Type Description
job (signal) => Promise<T> a function that receives a JobSignal. The signal is set when the plugin is turned off

Promise<T>

a promise of the value that the job returns


sleep(ms): Promise<void>;

Waits for a given time.

Parameter Type Description
ms number the time to wait, in milliseconds

Promise<void>


yield(): Promise<void>;

Lets the app do other work, and then continues. A long loop calls it between its steps.

Promise<void>