getAndProcess(done: () => void) { console.log('Getting all games'); var vm:Dota2 = this; var eventsToWaitOn = 3;// one for getting all the events, one for saving all the events var promise:any = new Promise(function (resolve:() => any){ // get the types of games... i.e. dota 2... Games.getAll(function (game:Game) { console.log('Getting all events for ' + game.name); vm.getNewEvents(game, function (event:Tournament) { vm.processEvent(event); }, function() { eventsToWaitOn--; if(eventsToWaitOn == 0) { resolve(); } console.log("Saved all games for - " + game.name); }); }, function() { eventsToWaitOn--; if(eventsToWaitOn == 0) { resolve(); } console.log("finished getting all games.") }); }); promise.then(done); }
Get(id: number): any { var promise = new Promise(function (resolve, reject) { var db = new context.Context(); db.connection.query('use net') db.connection.query('select id, name, mgt_address from deviceinfo where id = ?', [id], function (err, rows, fields) { if (err) throw err; resolve(rows); db.connection.end(); }); }); return promise.then(function (result) { return result; }); }