On Github jgrenat / devoxx-async-sync-slides
Jordane Grenat @JoGrenat
myAsyncCall() .then(data => console.log(data)) .catch(err => console.error(err));
myAsyncCall() .then(data => data.user) .then(user => console.log(user));
myAsyncCall() .then(userId => getUserAsync(userId)) .then(user => console.log(user)) .catch(error => console.error(error));
Promise.all([promise1, promise2]) .then(data => { console.log(data[0], data[1]); });
function *myGenerator() { yield 1; yield 2; }
const it = myGenerator(); console.log(it.next().value); // 1 console.log(it.next().value); // 2
function *myGenerator() { const value = yield 1; yield 2; yield value; }
const it = myGenerator(); console.log(it.next().value); // 1 console.log(it.next('Hello').value); // 2 console.log(it.next().value); // 'Hello'
function *myGenerator() { try { yield 1; } catch(err) { console.error(`Error: ${err}`); } }
const it = myGenerator(); console.log(it.next().value); // 1 it.throw('SomeError'); // Error: SomeError
function *myGenerator() { const user = yield getUserAsync(); console.log(user); }
const it = myGenerator(); const promise = it.next().value; promise.then(it.next); // show user
co(function*() { const user = yield getUserAsync(); console.log(user); });
async function myFunction() { const user = await getUserAsync(); console.log(user); } myFunction();
Stade 3: not in ES2016
const source = Observable .fromEvent(button, 'click'); source.subscribe(event => { console.log('Someone clicked!', event); });
Stade 1... but usable with RxJS
Jordane Grenat @JoGrenat
#DevoxxFR #AsyncSync @JoGrenat