Data Service API: Async question

I have a question regarding asynchronous callbacks. I think it’s easiest to start by showing an example of what I am trying to do.

var currentLog = logCollection.findById(currentId);
loadLog(currentLog, currentId);

My problem is that currentLog just isn’t defined by the time ‘loadLog()’ is being called. I know this can be solved using a callback function but all the examples in the documentation are synchronous and I’m just a little confused on how to format it. Do I need to define an Async() function? If you could just show me how it would work in this simple example I think I could put the rest together myself.

Thanks.

Hi Brandon,

The way your code is written, the invocation of findById is synchronous. The next line will not execute until the first line of code completes. So when you say that currentLog is not defined is not true. Perhaps findById returns null?

Regards,
Mark

Wow, you are very right. Thanks. I’ve been reading a lot about JS async/callbacks today and I think I just got myself confused. Sorry for the misguided question.