Skip to content

Instantly share code, notes, and snippets.

@freaktechnik
Forked from bbeamer/GlobalVariableProblem
Last active August 29, 2015 14:26
Show Gist options
  • Save freaktechnik/8902495eaacc7d406c0f to your computer and use it in GitHub Desktop.
Save freaktechnik/8902495eaacc7d406c0f to your computer and use it in GitHub Desktop.
//declare a promise to handle this treatement
//would be nice to call the same code many times
//use it as a function
Task.spawn(function* () {
//global variable
let id=[];
let db = yield Sqlite.openConnection({ path: myPath});
try {
let row = yield db.execute("SELECT id FROM 'plates'");
for ( i=0; i < row.length; i++) {
console.log("row["+ i +"] :" + row[i].getResultByIndex(0));
id.push(row[i].getResultByIndex(0));
}
}
finally {
yield db.close();
}
//Do whatever it is after the results are in.
console.log("id length:"+id.length);
id.forEach((idi, i) => console.log(i, idi));
});
//declare a promise to handle this treatement
//would be nice to call the same code many times
//use it as a function
let getIds = Task.async(function* () {
//global variable
let id=[];
let db = yield Sqlite.openConnection({ path: myPath});
try {
let row = yield db.execute("SELECT id FROM 'plates'");
for ( i=0; i < row.length; i++) {
console.log("row["+ i +"] :" + row[i].getResultByIndex(0));
id.push(row[i].getResultByIndex(0));
}
}
finally {
yield db.close();
}
return id;
});
let printIds = function(id) {
//Do whatever it is after the results are in.
console.log("id length:"+id.length);
id.forEach((idi, i) => console.log(i, idi));
};
getIds().then(printIds);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment