Sequential vs Parallel Tasks
Medium · Async
In Node you choose between for...of + await (one task at a time) and Promise.all (everything at once). Write async runTasks(tasks, mode) where each task is { name, ms, fail? } and mode is "sequential" or "parallel". Return the event log.
Each task: log "start <name>", wait ms (use sleep), then log "end <name>", or if fail is true, log "fail <name>" and throw.
- "sequential": run tasks one after another. Stop at the first failure (later tasks never start).
- "parallel": start all tasks at once and wait until ALL of them have finished, even if some fail (think Promise.allSettled).
When everything is finished, log "done" (in both modes, also after a failure) and return the log.