Exercício prático · Node.js

Practice lab: Bound work when the consumer is slow

do caderno de estudos · atualizado em 2 de outubro de 2026
Para quem vai encarar entrevista de Node.js2 min

Tente resolver a tarefa antes de consultar os critérios. Compare o resultado e explique o que mudou no seu raciocínio.

Tarefa e critérios de verificação

Task, 15 minutes: in a local scratch program, stream generated chunks into a deliberately slow Writable. Start with manual writes, record when write() returns false, then implement pause/resume on drain. Compare with pipeline(). Also make the destination fail after a few chunks and observe rejection and resource cleanup.

Check your work:

  • After false, no further chunks are written until drain or termination. The source does not keep an array of every chunk.
  • Increasing the total input should not make retained buffered data grow in direct proportion to the entire input. Observe buffering and memory over time, not one RSS sample.
  • Make the destination fail after a few chunks. The operation must reject and release the resources it owns.

Follow-up: explain why adding await around a CPU-heavy JavaScript loop does not move that work to another thread. Name a bounded worker-pool design and how callers behave when it is full.

No app, a tarefa fica visível e você pode revelar os critérios depois da tentativa. Use as notas para registrar sua solução.

Praticar este exercício no app