I am trying to send out network data. Essentially, the library I am using has a 16kb limit on message size, so I must break down larger messages and send them in chunks. A really simplified version of my code might look like:
function sendInChunks(buffers) {
send(buffers.shift()).then(sendInChunks.bind(undefined, buffers));
}
With a recursive implementation like this, the amount of data I can send is limited by the stack depth limits of whatever platform the code is running on. I was wondering if there is a way to send my data without the limitation of stack depth?
Note: In the actual implementation I have right now, I am actually using mutual recursion to do some checks after calling send. There is also some state from a higher scope used in both functions, but hopefully that wont change much.
EDIT: I am using es6 promises.