I am trying to query a MySQL database synchronously with sqljocky. I have a Load
class that runs the query and gets the data then imports the data into a User
object. The problem I am having is the Future that runs the query is not returning in time to return the object to the calling method.
DataObject user = new DataObject();
user.Get(1234);
// I cannot do anything here because the returned object is null
user.somethingElse();
DataObject Get(String ID){
return access.Load(this, ID);
}
// Runs query
Load(DataObject object, String ID){
// Set up query
String query = 'select * from users where ID = \'' + ID + '\'';
// Run query
var completer = new Completer.sync();
pool.query(query).then((result) {
result.listen((row) {
// Import into object
object.Import(row);
}, onDone: () {
completer.complete(object);
});
});
}