Remember things if you are using Future in Meteor
Posted By : Parveen Kumar Yadav | 27-Dec-2016
Meteor.methods({ test: function(FKmarketAccObj, userObj) { var fut = new Future(),result; var requestBodyHeaderObj = Meteor.call('getRequestBodyAndHeaderForAPI) if(requestBodyHeaderObj){ result = Meteor.call('getSearchOrdersAPI', requestBodyHeaderObj, userObj); } return fut.wait(); }, })
2)Even your server is also block for that user until he refresh the browser. There is not any single hit comes into server if you miss the return statement. So you must add return statement like:-
Meteor.methods({ test: function(FKmarketAccObj, userObj) { var fut = new Future(),result; var requestBodyHeaderObj = Meteor.call('getRequestBodyAndHeaderForAPI) if(requestBodyHeaderObj){ result = Meteor.call('getSearchOrdersAPI', requestBodyHeaderObj, userObj); } fut['return](result) // this statement must be add return fut.wait(); }, })
3)Never use return statement in loop like forEach or other because if you return future again and again for same than it will throw an error i.e:- Future resolved more than once. So to avoid this error always make a single return statement for future or always check for the length of array when it comes to last than only return.
In my personnel opinion avoid Future until its not required and use only once you study it in deapth Hope it will help Thanks!Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Parveen Kumar Yadav
Parveen is an experienced Java Developer working on Java, J2EE, Spring, Hibernate, Grails ,Node.js,Meteor,Blaze, Neo4j, MongoDB, Wowza Streaming Server,FFMPEG,Video transcoding,Amazon web services, AngularJs, javascript. He likes to learn new technologies