Overview

Defer allows you to schedule the time at which a execution will be executed. This is useful for example if you want send to a user an email 1 day after they sign up.

You can schedule a job in the future by using the delay function with a specific datetime or duration.

const delayFunc = delay(myFunc, new Date("1/1/24"));

The Defer scheduler only works with UTC datetime, so all datetime will be converted to UTC. For example if you delay something to 1 hour later, it will be align with your current timezone.

Example

import { delay } from "@defer/client";
import sendOnboardingEmail from "./defer/sendOnboardingEmail";

const delayedSendOnboardingEmail = delay(sendOnboardingEmail, "1h");
await delayedSendOnboardingEmail(userId);

Console

Even if the execution is scheduled for later you can still see it on the Console under the “Execution” tab.