Jeff Morrison (2014-09-11T16:59:19.000Z)
domenic at domenicdenicola.com (2014-09-17T22:18:48.357Z)
On 9/11/14, 10:22 AM, Florian Bösch wrote: > A -> B -> C -> D -> E changes to > > A -> B -> C -> D -> async E and causes > > A await -> B await -> C await -> D await -> async E > > And of course if A, B, C or D is used anywhere else it percolates > trough the entire call graph. Sort of true, but this is no worse than the status quo. ```js function A() { return B(); } function B() { return C(); } function D() { return D(); } function E() { return 42; } -> function E() { return new Promise(function(res, rej) { res(42); }); } ``` I said "sort of" above because it's also worth pointing out that, in some cases, outer plain functions can still consume async functions without needing to themselves become async. The case arises where the result of the outer plain function doesn't depend on the async result of the inner function. Many cases don't apply here, but it's worth pointing out to show that consumption of async functions isn't *always* stack-viral: ```js function add(a, b) { var logSuccess = log('adding ' + a + ' and ' + b); if (!logSucces) { console.warn('log failed!'); } return a + b; } function log(msg) { return logger.syncAppend(msg); } ``` changes to ```js function add(a, b) { log('adding ' + a + ' and ' + b).catch(function(res) { console.warn('log failed!'); }).done(); return a + b; } async function log(msg) { return logger.asyncAppend(msg); } ```