0

Full disclosure: I'm very new to the totally asynchronous model.

In my application there are a number of instances where information needs to be committed to the db, but the application can continue on without knowing the result. Is it acceptable to render a page before waiting for a db write to complete?

2 Answers 2

1

Yes. For example:

app.get('/', function(req, res, next) {
  res.jsonp({
    message: 'Hello World!'
  });
  var i = 0;
  while (true) {
    i++;
  }
});

When a user visits '/', he will see the result immediately. But if there is only one node instance is running, when the other user visits '/', he won't receive any response as the only instance is under a infinite loop.

If you have a lot of heavy work to do(for example, CPU-bound works), it's much better to use a message queue such as MSMQ and AMQP instead of having all the works done in the node instance.

Sign up to request clarification or add additional context in comments.

Comments

0

Sure. But how would you notify the user of an error if something did go wrong? Unless you're doing sockets or ajax or something, requests are the standard way.

1 Comment

For situations where the user has no need to know (i.e. various forms of logging). If an error occurs, it's handled on the server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.