0

I am recently use Parse as database to create an online app. However, I notice there is some problem with my code due to Parse's asynchronous propriety.

var courseList=[];

function getUserCourses(user){
var relation = user.relation("Courses");
relation.query().find({
success: function(courses){
    courseList = courses;
}
}); }

getUserCourses();
setTimeout(function(){console.log(courseList);},1500);

I just wonder instead of using setTimeout, is there is a better way to execute the Parse's query completely before running to the next line of code. Thanks!

Leon Meng
  • 1
  • 1
  • Nope. you must use callbacks. – Kevin B Jul 14 '16 at 19:29
  • Have you tried using promises? [http://colintoh.com/blog/staying-sane-with-asynchronous-programming-promises-and-generators](http://colintoh.com/blog/staying-sane-with-asynchronous-programming-promises-and-generators) – Craig Stroman Jul 14 '16 at 19:30

0 Answers0