-
• #2
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:
spiWriteCommand(X); return hspi_cmd(Y);
over and over, you could create an array, like:
var data = [ [[sizeH-1,0,0],0x0C], [[0xD7,0xD6,0x9D],0x2C], [0xA8,0x3A], ... ]; promise = new Promise(resolve => { function out() { var cmd = data.shift(); if (!cmd) return resolve(); spiWriteCommand(cmd[0]); hspi_cmd(cmd[1]).then(out); } out(); });
but I wonder if that's really better - i'd stick with what you have for now
-
• #3
Thanks again for the great help
-
• #4
before promises, I did non-blocking sequencing in a different way - see:
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
https://gist.github.com/brendena/fddc11a1660eb5d1f03a17466b314e66#file-gistfile1-txt-L97