Asyncawait in typescript
Transcript of 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
Fulfil the promise with async/awaitRan Wahle
Did I forgot to record my screen ?"
A little about me
Fullstack developer at Global-E Loves javascript
On the agenda
Promises Promises gets dirty Async / await Under the hood of async / await Summray
Promises
The pattern for async programming Has Become standard in es2015
Geolocation with promises demo
Demo – Geolocation and reverse Geocoding
Sink in promises
promise.then(result => doSecondAsync (result) .then(result2 => doThirdAsync(result2) .then(resut3 => doFourthAsync(result3)
.then(result4 => finish(result4)))));
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
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);
Geolocation and reverse Geocoding, Async/await
Generators
A function with an asterisk Can “stop” and yied a result Used by typescript when compiling async/await
Summary
async / await simplifies our promise code Typescript compilers produces generators You may use it when generators and promises are supported
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/
Thank you!
http://blogs.microsoft.co.il/ranw
Twitter: @ranwahle