Asyncawait in typescript

16
meetup.com/javascript-israel Thanks To Our Sponsors: SUPPORT THE COMMUNITY: SUBMIT YOUR LECTURE: facebook.com/groups/ jsisrael http://bit.ly/ jsil-apply http://bit.ly/ jsil-sponsor

Transcript of Asyncawait in typescript

Page 1: Asyncawait in typescript

meetup.com/javascript-israel

Thanks To Our Sponsors:

SUPPORT THE COMMUNITY:

SUBMIT YOUR LECTURE:

facebook.com/groups/jsisrael

http://bit.ly/jsil-apply

http://bit.ly/jsil-sponsor

Page 2: Asyncawait in typescript

Fulfil the promise with async/awaitRan Wahle

 

Page 3: Asyncawait in typescript

Did I forgot to record my screen ?"

Page 4: Asyncawait in typescript

A little about me

Fullstack developer at Global-E Loves javascript

Page 5: Asyncawait in typescript

On the agenda

Promises Promises gets dirty Async / await Under the hood of async / await Summray

Page 6: Asyncawait in typescript

Promises

The pattern for async programming Has Become standard in es2015

Page 7: Asyncawait in typescript

Geolocation with promises demo

Page 8: Asyncawait in typescript

Demo – Geolocation and reverse Geocoding

Page 9: Asyncawait in typescript

Sink in promises

promise.then(result => doSecondAsync (result) .then(result2 => doThirdAsync(result2) .then(resut3 => doFourthAsync(result3)

.then(result4 => finish(result4)))));

Page 10: Asyncawait in typescript

Async / await

Write asynchronous code in a “synchronous” way Async functions can use “await” expression The promises function ”returns” the actual result. The code after is the callback Exists in typescript since 1.7

Page 11: Asyncawait in typescript

Same sample with async / await

var result = await promise();var result2 = await doSecondAsync (result);var result3 = await doThirdAsync(result2);var result4 = await doFourthAsync(result3);finish(result4);

Page 12: Asyncawait in typescript

Geolocation and reverse Geocoding, Async/await

Page 13: Asyncawait in typescript

Generators

A function with an asterisk Can “stop” and yied a result Used by typescript when compiling async/await

Page 14: Asyncawait in typescript

Summary

async / await simplifies our promise code Typescript compilers produces generators You may use it when generators and promises are supported

Page 16: Asyncawait in typescript

Thank you!

[email protected]

http://blogs.microsoft.co.il/ranw

Twitter: @ranwahle