asyncawait in typescript
TRANSCRIPT
![Page 1: Asyncawait in typescript](https://reader035.vdocument.in/reader035/viewer/2022062522/58819c481a28ab1a398b45b3/html5/thumbnails/1.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062522/58819c481a28ab1a398b45b3/html5/thumbnails/2.jpg)
Fulfil the promise with async/awaitRan Wahle
![Page 3: Asyncawait in typescript](https://reader035.vdocument.in/reader035/viewer/2022062522/58819c481a28ab1a398b45b3/html5/thumbnails/3.jpg)
Did I forgot to record my screen ?"
![Page 4: Asyncawait in typescript](https://reader035.vdocument.in/reader035/viewer/2022062522/58819c481a28ab1a398b45b3/html5/thumbnails/4.jpg)
A little about me
Fullstack developer at Global-E Loves javascript
![Page 5: Asyncawait in typescript](https://reader035.vdocument.in/reader035/viewer/2022062522/58819c481a28ab1a398b45b3/html5/thumbnails/5.jpg)
On the agenda
Promises Promises gets dirty Async / await Under the hood of async / await Summray
![Page 6: Asyncawait in typescript](https://reader035.vdocument.in/reader035/viewer/2022062522/58819c481a28ab1a398b45b3/html5/thumbnails/6.jpg)
Promises
The pattern for async programming Has Become standard in es2015
![Page 7: Asyncawait in typescript](https://reader035.vdocument.in/reader035/viewer/2022062522/58819c481a28ab1a398b45b3/html5/thumbnails/7.jpg)
Geolocation with promises demo
![Page 8: Asyncawait in typescript](https://reader035.vdocument.in/reader035/viewer/2022062522/58819c481a28ab1a398b45b3/html5/thumbnails/8.jpg)
Demo – Geolocation and reverse Geocoding
![Page 9: Asyncawait in typescript](https://reader035.vdocument.in/reader035/viewer/2022062522/58819c481a28ab1a398b45b3/html5/thumbnails/9.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062522/58819c481a28ab1a398b45b3/html5/thumbnails/10.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062522/58819c481a28ab1a398b45b3/html5/thumbnails/11.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062522/58819c481a28ab1a398b45b3/html5/thumbnails/12.jpg)
Geolocation and reverse Geocoding, Async/await
![Page 13: Asyncawait in typescript](https://reader035.vdocument.in/reader035/viewer/2022062522/58819c481a28ab1a398b45b3/html5/thumbnails/13.jpg)
Generators
A function with an asterisk Can “stop” and yied a result Used by typescript when compiling async/await
![Page 14: Asyncawait in typescript](https://reader035.vdocument.in/reader035/viewer/2022062522/58819c481a28ab1a398b45b3/html5/thumbnails/14.jpg)
Summary
async / await simplifies our promise code Typescript compilers produces generators You may use it when generators and promises are supported
![Page 15: Asyncawait in typescript](https://reader035.vdocument.in/reader035/viewer/2022062522/58819c481a28ab1a398b45b3/html5/thumbnails/15.jpg)
Additional resources
Async / Await from MSDN blog:https://blogs.msdn.microsoft.com/typescript/2015/11/03/what-about-asyncawait/
Iterators ang generators from MDN:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators
Typescript site:http://www.typescriptlang.org/
![Page 16: Asyncawait in typescript](https://reader035.vdocument.in/reader035/viewer/2022062522/58819c481a28ab1a398b45b3/html5/thumbnails/16.jpg)
Thank you!
http://blogs.microsoft.co.il/ranw
Twitter: @ranwahle