3 ms·
I recently found that AngularJS has supports for promises. I replaced some of the callback code to use promises and it's a lot more readable. Callbacks: B
by fishtastic 13y ago
I recently found that AngularJS has supports for promises. I replaced some of the callback code to use promises and it's a lot more readable.
Callbacks:
Backend.CallA(param, function() {
aDone = true;
if (aDone && bDone) { doC(); }
});
Backend.CallB(param, function() {
bDone = true;
if (aDone && bDone) { doC(); }
});
Promises:
var promiseA = Backend.CallA(param);
var promiseB = Backend.CallB(param);
$q.all([promiseA, promiseB]).then(doC);
- danabramov 13y agoIIRC Angular's promises are based on stripped down version of Kris Kowal's Q. You may want to check it out: https://github.com/kriskowal/q https://github.com/kriskowal/q
- jeremya 13y agoAs of AngularJS version 1.2, the promises provider ($q) is fully Promises/A+ compliant. http://blog.angularjs.org/2013/11/angularjs-120-timely-delivery.html http://blog.angularjs.org/2013/11/angularjs-120-timely-deliv...