Hacker News new | past | comments | ask | show | jobs | submit login

When you actually look at the code, and how you're executing the functions, it makes sense that Promise.all doesn't magically make your promises run in serial.

      knex.schema.renameTable('tomatoes', 'potatoes'),
      knex.schema.table('potatoes', (table) => table.string('name'))
Promise.all doesn't execute the functions - you're doing that yourself. The argument you're passing to Promise.all is just an array of already kicked-off promises. Consider it rewritten as:

    const promise1 = knex.schema.renameTable('tomatoes', 'potatoes’);
    const promise2 = knex.schema.table('potatoes', (table) => table.string('name’));
    Promise.all([promise1, promise2]);
Promise.all is just create a new Promise for you that is resolved when the promises you pass in are all resolved.

In fact, looking at the 'solution' to this (Promise.series), it still suffers from the same problem. See this demo of it still not working https://tonicdev.com/56da37cb0ba4470d00919c26/56da37cb0ba447...

Awesome find! I was not considering that a promise is executing as soon as it is created, and this is why the implementation still results in parallel execution.

I've gone back to the drawing board, and I've updated my post accordingly with a better solution using reduce. I've also used your demo above as an example and credited you in my article (please let me know if that is not OK, and I will take it down).

Thanks again!

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact