You're #${position} in line.
`, }), }) }, }, }) ``` ```ts import { db, services } from '@cloudwerk/bindings' export async function POST(request: Request) { const { email } = await request.json() const result = await db.prepare(` INSERT INTO waitlist (email) VALUES (?) RETURNING id `).bind(email).first() await services.email.sendWelcome({ to: email, position: result.id }) return Response.json({ success: true, position: result.id }) } ``` Chapter 3 ### Don't Block the Response Emails are slowing down signups. Let's queue them. Sending emails inline adds latency. Move them to a queue and respond instantly. Cloudwerk queues are just files—define a handler and start sending. \+ Queues Cloudwerk Project Explorer `app/` `├── page.tsx` `├── api/` `│ └── waitlist/` `│ └── route.ts` `├── services/` `│ └── email/` `│ └── service.ts` `└── queues/` `└── emails.ts` 📘 emails.ts app/queues/emails.ts 📘 route.ts app/api/waitlist/route.ts ```ts import { defineQueue } from '@cloudwerk/queue' import { services } from '@cloudwerk/bindings' interface WelcomeEmail { to: string position: number } export default defineQueue