ydn-db async operation need to assign value to variable

65 views Asked by At

I'm unable to assign variable from async operation using callback . .done didn't assign value to variable. Here my code :

var someGlobalVar = 0;
dbs.count('cfs_init').done(function(x) {

console.log('Total : ' + x); 
someGlobalVar = x;
}); 

console.log(someGlobalVar); // 0 
1

There are 1 answers

0
Kyaw Tun On

Your assignment works if you manually (or in setTimeout function) execute console.log(someGlobalVar);, after receiving done callback.

You are executing it before done callback and hence it is still 0.