How to hint an asynchronous operation with a JavaScript promise? -


For learning purposes, I want to show how to help resolve the dependency at the time of database operation in Javascript can do.

So, I want to show this:

  db.find (14);   

Actually consumes the time behind the curtain.

How can I explain the dependence and a possible solution at this time which promises?

Do I still have this:

  // Take the data store operation time function _findByUsername (username) {var user = _.findWhere (user, {username} : Username}); If (! User) {Promise.reject (new error ("user not found.")); } Return Plaintiff. User (user); }   

One option may be to use the function of the bluebird and a comment Can be added as follows:

  findByUsername (username) {/ * simulates the behavior of a database operation / / Promise.delay return (10). Then the setter (_. FindWhere (user, {username: user name})}    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -