Performance: Why background processing handles heavy tasks
This concept affects the responsiveness and interaction speed of a web application by offloading heavy tasks from the main request thread.
async handleRequest() { this.queueBackgroundTask(); return { status: 'queued' }; } // Background worker processes the heavy task separately
async handleRequest() { await this.processHeavyTask(); return { status: 'done' }; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy task in request handler | Minimal | 0 | 0 | [X] Bad |
| Heavy task in background queue | Minimal | 0 | 0 | [OK] Good |
@Processor('email')
export class EmailProcessor {
@Process('sendEmail')
async handleSendEmail(job: Job) {
console.log('Sending email to', job.data.to);
}
}@Processor('tasks')
export class TaskProcessor {
@Process('heavyTask')
handleHeavyTask(job: Job) {
// missing async keyword
await doHeavyWork(job.data);
}
}Pass the test and this pattern moves unknown