• Basically i have some code that will send a command out and then wait for the busy flag pin pulled high. To link these things together i just have a bunch of promises that chain together. Is that bad practice. As in will it be bad for performance to do something like this.

    Example of what i mean

  • 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

  • Thanks again for the great help

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Is there any penalty to using a lot of chained promises together

Posted by Avatar for user156811 @user156811