No promises: asynchronous JavaScript with only generators
Two ECMAScript 6 [1] features enable an intriguing new style of asynchronous JavaScript code: promises [2] and generators [3] . This blog post explains this new style and presents a way of using it without promises. Overview Normally, you make a function calls like this: let result = func(···); console.log(result); It would be great if this style of invocation also worked for functions that perform tasks (such as downloading a file) asynchronously. For that to work, execution of the previous code would have to pause until func() returns with a result. Before ECMAScript 6, you couldn’t pause and resume the execution of code, but you could simulate it, by putting console.log(result) into a callback, a so-called continuation [4] . The continuation is triggered by asyncFunc() , once it is done: asyncFunc('http://example.com', result => { console.log(result); }); Promises [2] are basically a smarter way of managing callbacks: asyncFunc('http...