The defer.cron(fn, schedule, options) function allows to run a function recurrently in the background.

Example:

import { defer } from "@defer/client";

const sayHello = async () => console.log(`hello!`);

export default defer.cron(sayHello, "5 0 * * *");
A function wrapped by defer.cron() cannot have arguments

Schedule expression

schedule
string

A valid CRON expression. Determines the schedule for your background job.

Examples:

export default defer.cron(sayHello, "*/5 * * * *");

Options

The defer.cron() function takes the same options as defer().