↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

Code Smell 155 — Multiple Promises

The page says that waiting for promises in a sorted order can block work unnecessarily. If the rule is to wait for all operations, the code should let them run in parallel and collect the results together.

Reading notes
#

  • The smell is described as indeterminism and a performance bottleneck.
  • The suggested solution is to wait for all promises at once.
  • The context compares this to semaphores and the need to wait until all conditions are met, regardless of ordering.
  • The wrong example awaits fetchOne before fetchTwo, which prevents parallel execution.
  • The right example uses Promise.all with fetchOne and fetchTwo together.
  • The smell is marked as semi-automatic and semantic, with linters able to find related promise-waiting patterns.
  • The conclusion says software should stay close to real-world business rules and avoid forcing a particular order when the rule only requires all operations to finish.