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.
Example
Section titled “Example”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 }});Methods
Section titled “Methods”run<T>(job): Promise<T>;Runs a job in the background.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Description |
|---|---|
T |
the type of the value that the job returns |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
job |
(signal) => Promise<T> |
a function that receives a JobSignal. The signal is set when the plugin is turned off |
Returns
Section titled “Returns”Promise<T>
a promise of the value that the job returns
sleep()
Section titled “sleep()”sleep(ms): Promise<void>;Waits for a given time.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
ms |
number |
the time to wait, in milliseconds |
Returns
Section titled “Returns”Promise<void>
yield()
Section titled “yield()”yield(): Promise<void>;Lets the app do other work, and then continues. A long loop calls it between its steps.
Returns
Section titled “Returns”Promise<void>
