Schedule a follow-up
Fire a task only after activity goes silent. Each event resets the clock with a single DB update, no scheduler churn.
Use this to
- Send a re-engagement email 3 days after a user's last login
- Remind a team member about an unreplied thread after 48 hours
- Nudge a user to finish a form they started but haven't submitted in 24 hours
- Prompt a seller to update their listing if they haven't edited it in a week
- Auto-release a collaborative-editing lock 5 minutes after the holder stops typing
- Cancel a stalled chunked upload if no new chunk arrives in 60 seconds
Code
Debounce on every user activity
// each call updates one row in Postgres, // no scheduler reschedule, no churn on the wake-up await dk.debounce("follow-up", { key: user.id, wait: "3d", });
When the time comes, send the follow-up
dk.handle("follow-up", async ({ key }) => { const user = await db.users.find(key); if (wasActiveRecently(user)) return; // safety check await sendReengagementEmail(user.email); });
npm install delaykit
bun add delaykit