• Suspends workflow execution for a durable, crash-safe duration. Unlike setTimeout, this sleep survives process restarts — the engine persists the wake-up time and resumes the workflow when the timer expires.

    On replay, sleepFor returns immediately with the stored duration (no actual waiting occurs). This makes it safe for deterministic re-execution.

    Accepts any human-readable duration string parsed by the ms module: '5 seconds', '30s', '2 minutes', '1m', '1 hour', '2h', '1 day', '7d'.

    import { Durable } from '@hotmeshio/hotmesh';

    // Simple delay before continuing
    export async function reminderWorkflow(userId: string): Promise<void> {
    const { sendReminder } = Durable.workflow.proxyActivities<typeof activities>();

    // Wait 24 hours (survives server restarts)
    await Durable.workflow.sleepFor('24 hours');
    await sendReminder(userId, 'Your trial expires tomorrow');

    // Wait another 6 days
    await Durable.workflow.sleepFor('6 days');
    await sendReminder(userId, 'Your trial has expired');
    }
    // Exponential backoff with retry loop
    export async function pollingWorkflow(resourceId: string): Promise<string> {
    const { checkStatus } = Durable.workflow.proxyActivities<typeof activities>();

    for (let attempt = 0; attempt < 10; attempt++) {
    const status = await checkStatus(resourceId);
    if (status === 'ready') return status;

    // Exponential backoff: 1s, 2s, 4s, 8s, ...
    const delay = Math.pow(2, attempt);
    await Durable.workflow.sleepFor(`${delay} seconds`);
    }
    return 'timeout';
    }
    // Race a sleep against an activity
    const [result, _] = await Promise.all([
    activities.fetchData(id),
    Durable.workflow.sleepFor('30 seconds'),
    ]);

    Parameters

    • duration: string

      A human-readable duration string.

    Returns Promise<number>

    The resolved duration in seconds.