SlideShare a Scribd company logo
ITERA UKRAINE 2017
ASYNC
JAVASCRIPT
OLEKSANDR SKACHKOV @alSkachkov
β€’ callbacks
β€’ promises
β€’ async function
β€’ async generator
Async Javascript
Journey from callback to async generator
ASYNC JAVASCRIPT
β€’ Is JavaScript really async?
β€’ JavaScript as language was sync until ES6
β€’ What about: Event Loop, setTimeout, events and etc?
It is part of the W3C spec
β€’ Promise – the first async feature in JavaScript
IN THE BEGINNING WAS THE FUNCTION
β€’ Callback function
is a function that is passed to another function as a
parameter
β€’ Problem with using callback
β€’ synchronization
β€’ callback hell
β€’ not clear flow
β€’ Promise – 1976
β€’ Promise pipeline – 1988
PROMISES
Promises in computer science
TERMS
Future vs Promise vs Deferred:
β€’ Future
β€’ Promise
β€’ Deferred
- is the value
- is the function that sets the value to future
- is an object than can create a promise
Operations of setting value is fulfill or resolve promise
PROMISES
Analogs in other popular languages
β€’ C++ ->std::feature / std:promise
β€’ .Net ->Task
β€’ Java ->CompletableFuture
PROMISES IN JS
History in JS:
β€’ Dojo - Deferred API
β€’ Promise/A+ specification
β€’ jQuery deferred and Q/$Q
β€’ Promises is part of ES6
PROMISES IN JS
β€’ What is Promise in ES6?
The Promise object is used for asynchronous computations. A Promise represents a value which may be available now, or in
the future, or never.
β€’ Promise’s states:
β€’ fulfilled
β€’ pending
β€’ rejected
PROMISES IN JS
β€’ How to create?
new Promise()
β€’ Promise.resolve
β€’ Promise.reject
PROMISES IN JS
β€’ Promise object has methods:
β€’ then
β€’ catch
β€’ finally - soon
FLOW WITH PROMISES
Flow with promises:
β€’ Promise.all
β€’ Promise.race
CAN WE USE PROMISE?
Global support 77%
Yes we can
ASYNC FUNCTION
β€’ Coroutine – async function
β€’ History:
β€’ Coroutine is coined by Melvin Conway in 1958
β€’ Inspired by C#/F#, started in 2014
by Luke Hoban and finished by
Brian Terlson.
CAN WE MAKE BETTER?
ASYNC FUNCTION
Analogs
β€’ .Net - C# Async function
β€’ Java – Spring (directive @Async)
β€’ C++ - different approaches on is std::async
ASYNC FUNCTION
β€’ async function
β€’ async/await keyword
β€’ async function always returns Promise
ASYNC FUNCTION
β€’ async arrow function
β€’ async method in class
ASYNC FUNCTION
Throw exception in async function
reject in await
can be handled by try/catch
IS FUNCTION ASYNC FUNCTION?
typeof or toString?
Symbol.toStringTag and Object.prototype.toString.call(…)
No
FLOW WITH ASYNC FUNCTION
Promise
Async function
CAN WE USE ASYNC FUNCTION?
Yes we can
Global support 65%
CAN WE MAKE BETTER?
ASYNC GENERATOR
Started developed by Kevin Smith in 2014, and finished by Domenic Denicola
in 2017. Currently it is on STAGE - 3
Analogs:
β€’ .Net C# - AsyncEnumerator
β€’ C++ - Proposals n4244 & N3858(C++17) - Resumable Functions (resume/await)
β€’ Java – Not supported
ASYNC GENERATOR. RUN TIME
β€’ Async generator return
iterator object
β€’ Async generator does not
execute its body immediately
ASYNC GENERATOR
Async generator return iterator
with methods:
β€’ next
β€’ return
β€’ throw
ASYNC GENERATOR
New keywords: for await, yield *
IS FUNCTION ASYNC GENERATOR?
typeof or toString?
Symbol.toStringTag and Object.prototype.toString.call(…)
CAN WE USE ASYNC GENERATOR?
Not, but:
β€’ only in Chrome Canary with --js-flags=--harmony-async-iteration
β€’ my MacBook
QUESTION?
Async js
Async js
Async js
Async js
Async js
Async js
Async js
Async js
Async js
Async js
Async js
Async js
Async js
Async js

More Related Content

PDF
Asynchronous javascript
PDF
Introducing Async/Await
PDF
Getting Started with Spring for GraphQL
PDF
Introduction to GraphQL
PDF
How to GraphQL: React Apollo
PDF
Asynchronous JavaScript Programming
PDF
Spring GraphQL
PPT
TypeScript Presentation
Asynchronous javascript
Introducing Async/Await
Getting Started with Spring for GraphQL
Introduction to GraphQL
How to GraphQL: React Apollo
Asynchronous JavaScript Programming
Spring GraphQL
TypeScript Presentation

What's hot (20)

PPTX
Modern JS with ES6
PPTX
Rxjs ngvikings
PDF
gRPC: The Story of Microservices at Square
PPTX
An intro to GraphQL
PPTX
Spring Webflux
PDF
Asynchronous JavaScript Programming with Callbacks & Promises
PDF
Intro to GraphQL
PDF
C# ASP.NET WEB API APPLICATION DEVELOPMENT
PDF
REST vs GraphQL
PPTX
Object Oriented Programming In JavaScript
PPTX
ReactJS presentation.pptx
PPT
Graphql presentation
PPTX
Introduction to graphQL
PPTX
Rxjs ppt
PDF
Introduction to RxJS
PDF
React and redux
PPTX
Introducing Swagger
ODP
Introduction to Swagger
PPTX
Reactive programming intro
PDF
Angular Observables & RxJS Introduction
Modern JS with ES6
Rxjs ngvikings
gRPC: The Story of Microservices at Square
An intro to GraphQL
Spring Webflux
Asynchronous JavaScript Programming with Callbacks & Promises
Intro to GraphQL
C# ASP.NET WEB API APPLICATION DEVELOPMENT
REST vs GraphQL
Object Oriented Programming In JavaScript
ReactJS presentation.pptx
Graphql presentation
Introduction to graphQL
Rxjs ppt
Introduction to RxJS
React and redux
Introducing Swagger
Introduction to Swagger
Reactive programming intro
Angular Observables & RxJS Introduction
Ad

Similar to Async js (20)

PDF
The evolution of asynchronous javascript
PDF
JavaScript promise
PDF
The Evolution of Asynchronous Javascript - Alessandro Cinelli - Codemotion Mi...
PDF
Introduction to Node JS2.pdf
PPTX
Async discussion 9_29_15
PDF
Asynchronous Programming. Talk from ESUG2024
Β 
PDF
JavaScript, un langage plein de promesses
PDF
Introduction to Object Oriented Javascript
PDF
The art of concurrent programming
PPTX
An introduction to Object Oriented JavaScript
PDF
Avoiding callback hell with promises
PDF
Async js - Nemetschek Presentaion @ HackBulgaria
ODP
Introduction of Object Oriented JavaScript
PPTX
JavaScript Promises
PDF
Getting Comfortable with JS Promises
PDF
Asynchronous development in JavaScript
PDF
Promises, Promises: Mastering Async I/O in Javascript with the Promise Pattern
PDF
The evolution of asynchronous JavaScript
PDF
JavaScript Promises Simplified [Free Meetup]
PDF
Boom! Promises/A+ Was Born
The evolution of asynchronous javascript
JavaScript promise
The Evolution of Asynchronous Javascript - Alessandro Cinelli - Codemotion Mi...
Introduction to Node JS2.pdf
Async discussion 9_29_15
Asynchronous Programming. Talk from ESUG2024
Β 
JavaScript, un langage plein de promesses
Introduction to Object Oriented Javascript
The art of concurrent programming
An introduction to Object Oriented JavaScript
Avoiding callback hell with promises
Async js - Nemetschek Presentaion @ HackBulgaria
Introduction of Object Oriented JavaScript
JavaScript Promises
Getting Comfortable with JS Promises
Asynchronous development in JavaScript
Promises, Promises: Mastering Async I/O in Javascript with the Promise Pattern
The evolution of asynchronous JavaScript
JavaScript Promises Simplified [Free Meetup]
Boom! Promises/A+ Was Born
Ad

More from Alexandr Skachkov (7)

PDF
WebAssembly in Houdini CSS, is it possible?
PDF
WebAssembly vs JavaScript: What is faster?
PDF
How to run WebAssembly in your React Web Application
PDF
WebAssemlby vs JavaScript
PPTX
WebAssembly overview. KievJS meetup
PPTX
JavaScript Metaprogramming with ES 2015 Proxy
PDF
WebAssembly Overview
WebAssembly in Houdini CSS, is it possible?
WebAssembly vs JavaScript: What is faster?
How to run WebAssembly in your React Web Application
WebAssemlby vs JavaScript
WebAssembly overview. KievJS meetup
JavaScript Metaprogramming with ES 2015 Proxy
WebAssembly Overview

Recently uploaded (20)

PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PPTX
Internet___Basics___Styled_ presentation
PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PPT
Ethics in Information System - Management Information System
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PDF
Sims 4 Historia para lo sims 4 para jugar
PPTX
Introuction about WHO-FIC in ICD-10.pptx
PDF
Paper PDF World Game (s) Great Redesign.pdf
PDF
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
PPTX
Introduction to Information and Communication Technology
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PPTX
Funds Management Learning Material for Beg
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PDF
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PPT
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
An introduction to the IFRS (ISSB) Stndards.pdf
Internet___Basics___Styled_ presentation
introduction about ICD -10 & ICD-11 ppt.pptx
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
Ethics in Information System - Management Information System
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
Sims 4 Historia para lo sims 4 para jugar
Introuction about WHO-FIC in ICD-10.pptx
Paper PDF World Game (s) Great Redesign.pdf
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
Introduction to Information and Communication Technology
Slides PPTX World Game (s) Eco Economic Epochs.pptx
Funds Management Learning Material for Beg
Slides PDF The World Game (s) Eco Economic Epochs.pdf
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
Introuction about ICD -10 and ICD-11 PPT.pptx
Job_Card_System_Styled_lorem_ipsum_.pptx
Unit-1 introduction to cyber security discuss about how to secure a system

Async js

  • 2. β€’ callbacks β€’ promises β€’ async function β€’ async generator Async Javascript Journey from callback to async generator
  • 3. ASYNC JAVASCRIPT β€’ Is JavaScript really async? β€’ JavaScript as language was sync until ES6 β€’ What about: Event Loop, setTimeout, events and etc? It is part of the W3C spec β€’ Promise – the first async feature in JavaScript
  • 4. IN THE BEGINNING WAS THE FUNCTION β€’ Callback function is a function that is passed to another function as a parameter β€’ Problem with using callback β€’ synchronization β€’ callback hell β€’ not clear flow
  • 5. β€’ Promise – 1976 β€’ Promise pipeline – 1988 PROMISES Promises in computer science
  • 6. TERMS Future vs Promise vs Deferred: β€’ Future β€’ Promise β€’ Deferred - is the value - is the function that sets the value to future - is an object than can create a promise Operations of setting value is fulfill or resolve promise
  • 7. PROMISES Analogs in other popular languages β€’ C++ ->std::feature / std:promise β€’ .Net ->Task β€’ Java ->CompletableFuture
  • 8. PROMISES IN JS History in JS: β€’ Dojo - Deferred API β€’ Promise/A+ specification β€’ jQuery deferred and Q/$Q β€’ Promises is part of ES6
  • 9. PROMISES IN JS β€’ What is Promise in ES6? The Promise object is used for asynchronous computations. A Promise represents a value which may be available now, or in the future, or never. β€’ Promise’s states: β€’ fulfilled β€’ pending β€’ rejected
  • 10. PROMISES IN JS β€’ How to create? new Promise() β€’ Promise.resolve β€’ Promise.reject
  • 11. PROMISES IN JS β€’ Promise object has methods: β€’ then β€’ catch β€’ finally - soon
  • 12. FLOW WITH PROMISES Flow with promises: β€’ Promise.all β€’ Promise.race
  • 13. CAN WE USE PROMISE? Global support 77% Yes we can
  • 14. ASYNC FUNCTION β€’ Coroutine – async function β€’ History: β€’ Coroutine is coined by Melvin Conway in 1958 β€’ Inspired by C#/F#, started in 2014 by Luke Hoban and finished by Brian Terlson. CAN WE MAKE BETTER?
  • 15. ASYNC FUNCTION Analogs β€’ .Net - C# Async function β€’ Java – Spring (directive @Async) β€’ C++ - different approaches on is std::async
  • 16. ASYNC FUNCTION β€’ async function β€’ async/await keyword β€’ async function always returns Promise
  • 17. ASYNC FUNCTION β€’ async arrow function β€’ async method in class
  • 18. ASYNC FUNCTION Throw exception in async function reject in await can be handled by try/catch
  • 19. IS FUNCTION ASYNC FUNCTION? typeof or toString? Symbol.toStringTag and Object.prototype.toString.call(…) No
  • 20. FLOW WITH ASYNC FUNCTION Promise Async function
  • 21. CAN WE USE ASYNC FUNCTION? Yes we can Global support 65%
  • 22. CAN WE MAKE BETTER?
  • 23. ASYNC GENERATOR Started developed by Kevin Smith in 2014, and finished by Domenic Denicola in 2017. Currently it is on STAGE - 3 Analogs: β€’ .Net C# - AsyncEnumerator β€’ C++ - Proposals n4244 & N3858(C++17) - Resumable Functions (resume/await) β€’ Java – Not supported
  • 24. ASYNC GENERATOR. RUN TIME β€’ Async generator return iterator object β€’ Async generator does not execute its body immediately
  • 25. ASYNC GENERATOR Async generator return iterator with methods: β€’ next β€’ return β€’ throw
  • 26. ASYNC GENERATOR New keywords: for await, yield *
  • 27. IS FUNCTION ASYNC GENERATOR? typeof or toString? Symbol.toStringTag and Object.prototype.toString.call(…)
  • 28. CAN WE USE ASYNC GENERATOR? Not, but: β€’ only in Chrome Canary with --js-flags=--harmony-async-iteration β€’ my MacBook

Editor's Notes

  • #4: JS Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ Π² асинхронном ΠΎΠΊΡ€ΡƒΠΆΠ΅Π½ΠΈΠΈ https://www.w3.org/TR/html5/webappapis.html#timers https://www.w3.org/TR/html5/webappapis.html#event-loops Streams https://streams.spec.whatwg.org
  • #5: Piramide of The DOOM
  • #6: ΠŸΡ€ΠΎΠΌΠΈΡΡ‹ извСстны с 1976 Π‘Π°Ρ€Π±Ρ€Π° Лискова ΠœΠ°Ρ€ΠΊ Π‘ΠΈΠΌΠΎΠ½
  • #9: Dojo - 2009 JQuery – 2013 (me) Q - 2014 ES6 – 2014/2015
  • #10: pending: initial state, not fulfilled or rejected. fulfilled: meaning that the operation was completed successfully. rejected: meaning that the operation failed.
  • #20: http://gs.statcounter.com/ Babel для старых Π±Ρ€Π°ΡƒΠ·Π΅Ρ€ΠΎΠ² ΠΈΠ»ΠΈ ΠΏΠΎΠ»ΠΈΡ„ΠΈΠ»
  • #21: Part of the ES2017 Π‘ΠΎΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ°Β (Π°Π½Π³Π». coroutine) β€” ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹, ΠΎΠ±ΠΎΠ±Ρ‰Π°ΡŽΡ‰ΠΈΠΉ понятиС ΠΏΠΎΠ΄ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅Ρ‚ мноТСство Π²Ρ…ΠΎΠ΄Π½Ρ‹Ρ… Ρ‚ΠΎΡ‡Π΅ΠΊ (Π° Π½Π΅ ΠΎΠ΄Π½Ρƒ, ΠΊΠ°ΠΊ ΠΏΠΎΠ΄ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ°), остановку ΠΈ ΠΏΡ€ΠΎΠ΄ΠΎΠ»ΠΆΠ΅Π½ΠΈΠ΅ выполнСния с сохранСниСм ΠΎΠΏΡ€Π΅Π΄Π΅Π»Ρ‘Π½Π½ΠΎΠ³ΠΎ полоТСния.
  • #22: Part of the ES2017 Π‘ΠΎΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ°Β (Π°Π½Π³Π». coroutine) β€” ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹, ΠΎΠ±ΠΎΠ±Ρ‰Π°ΡŽΡ‰ΠΈΠΉ понятиС ΠΏΠΎΠ΄ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅Ρ‚ мноТСство Π²Ρ…ΠΎΠ΄Π½Ρ‹Ρ… Ρ‚ΠΎΡ‡Π΅ΠΊ (Π° Π½Π΅ ΠΎΠ΄Π½Ρƒ, ΠΊΠ°ΠΊ ΠΏΠΎΠ΄ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ°), остановку ΠΈ ΠΏΡ€ΠΎΠ΄ΠΎΠ»ΠΆΠ΅Π½ΠΈΠ΅ выполнСния с сохранСниСм ΠΎΠΏΡ€Π΅Π΄Π΅Π»Ρ‘Π½Π½ΠΎΠ³ΠΎ полоТСния.
  • #28: Symbol.toStringTag is property
  • #31: https://babeljs.io/repl/#?babili=false&evaluate=true&lineWrap=false&presets=es2015%2Creact%2Cstage-2&targets=&browsers=&builtIns=false&debug=false&code_lz=IYZwngdgxgBAZgV2gFwJYHsL3egFAShgG8AoGGYAd2FWRgHIBGegbjJgCcBTZBDregCZWJAL4kScHARZA
  • #40: Symbol.toStringTag is property