• What you're doing there seems really nice and clean.

    The downside is that when it first starts, it's using a bit of memory to store all the promises all at once, but it's not really that bad.

    If you nested everything with callbacks you'd avoid that up-front memory usage, but then it ends up re-parsing all the functions inside each time it goes through an iteration, so there are downsides there too (in addition to it looking awful).

    Only other thing I might mention is if you're just doing:

    return hspi_cmd(Y);

    over and over, you could create an array, like:

    var data = [
    promise = new Promise(resolve => {
      function out() {
        var cmd = data.shift();
        if (!cmd) return resolve();

    but I wonder if that's really better - i'd stick with what you have for now


Avatar for Gordon @Gordon started