Patterns

A catalog of things you can do with DelayKit

Each pattern maps a concrete problem to the DelayKit API. If you’re not sure which one you need, start with Send a reminder or Debounce a flurry.

Send a reminder

Schedule a notification for later. The handler checks current state when it fires.

dk.schedule("remind", { delay: "24h" })
handler decides whether to send

Expire something

Run cleanup the moment a deadline passes. Invitations, trials, holds.

dk.schedule("expire-trial", { delay: "14d" })
handler skips if already resolved

Debounce a flurry

Collapse fifty events into one action. Durable across restarts.

dk.debounce("reindex", { wait: "5s" })
optional maxWait to cap the window

Retry with backoff

Something failed during a request. Defer the retry instead of blocking the response.

dk.schedule("retry-charge", { delay: "1m" })
handler retries with configurable backoff

Coalesce into a digest

Collapse a burst of events into one handler run per window. The handler fires at the end of the window with the latest state.

dk.throttle("digest", { wait: "1m" })
one handler run per window — many calls coalesce

Schedule a follow-up

Run a task after a period of user inactivity. Each call resets the clock.

dk.debounce("follow-up", { key, wait: "3d" })
cheap to call from every request

Deferred cleanup

Fire-and-forget maintenance. Schedule it once, let it run.

dk.schedule("cleanup", { delay: "1h" })
no state check, no cancel — just runs

Renew before expiry

Refresh a token, lease, or session a few minutes before it expires.

dk.schedule("refresh", { delay: "55m" })
reschedule on each successful renewal

Dead man's switch

Alarm when something stops happening. The absence of an event is the trigger.

dk.schedule("missed-heartbeat", { delay: "5m" })
cancel on each ping, fires only on silence

Poll until done

Wait on async work by checking back periodically until it's ready — or until you give up.

dk.schedule("check", { delay: "2m" })
handler reschedules itself if not ready yet

Schedule a drip sequence

Schedule every step of an onboarding or trial drip up front. Each handler checks current state when it fires.

dk.schedule("drip-day-3", { delay: "3d" })
one job per step, all queued at signup

Delayed publish

Publish a post, send an email, or release content at a specific future time.

dk.schedule("publish", { at: post.publishAt })
edit or cancel any time before it fires