BackgroundTaskRun
What a task receives when the OS runs it.
Utilisation
Skip work when a background run has no time left.
// Skip work when a background run has no time left.
import { backgroundTasks, type BackgroundTaskRun, type BackgroundTaskStatus } from 'kuito';
backgroundTasks.define('refresh', async (run: BackgroundTaskRun) => {
if (run.deadline - Date.now() < 5000) return;
const response = await fetch('https://example.com/feed', { signal: AbortSignal.timeout(4000) });
if (!response.ok) throw new Error(`Refresh failed: ${response.status}`);
});
export async function enableRefresh() {
const status: BackgroundTaskStatus = await backgroundTasks.status();
if (status === 'available') await backgroundTasks.schedule('refresh');
}
// Declare refresh in kuito.config.ts before rebuilding the native app.Déclaration du type
export type BackgroundTaskRun = {
name: string;
/** When the OS stops the run, in milliseconds since the epoch. Finish before it. */
deadline: number;
};Membres 2
| Nom | Type | Requis | Description |
|---|---|---|---|
name | string | Oui | — |
deadline | number | Oui | When the OS stops the run, in milliseconds since the epoch. Finish before it. |
Généré depuis les déclarations TypeScript publiques : signatures, props et valeurs par défaut viennent de la source vérifiée, les descriptions de sa JSDoc. Aucune valeur par défaut n'est inventée.