Is providing tutorial URL allowed?

What is a good way to retrying providing response in node.js several times?

  • The case is, that I have a method, that is doing one of three things. It get's an object from the database. If it not present then creates it but with empty url field. After that it generates an image, which can take a pretty long time (lets say 2s), upload it to s3 (another 2s) and if upload is finished add the url to the object, or if not, deletes that object. If the object exists but it doesn't have url, it SHOULD retry all after 500ms for example. If the object url is present, stream the file from that url. I was trying to use setTimeout for that, but if I have 1000 connections at the same time, I get Error: accept EMFILE, (to many files opened) var refresh = false; module.exports.imageGet = function(req, res, next){ if (!refresh) { refresh = true; res.send('ok'); } else { var timeout = setTimeout(module.exports.imageGet,500,req,res,next); } }; It's not about timeout cleaning, because I had a code that was cleaning them and It didn't help. It seams that the setTimeout by itself makes that works bad.

  • Answer:

    Take a look at the asyncJs package: https://github.com/caolan/async/blob/master/README.md#retry There's an ongoing debate between promise based flows and libraries such as async or step. I'll leave that up to you.

Ruben Cordeiro at Quora Visit the source

Was this solution helpful to you?

Other answers

eeek...don't use setTimeout look at the npm package q

Jonathan Jaffe

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.