Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let sayHello = () => {
- return new Promise((resolve) => {
- setTimeout(() => {
- console.log('1. Hello all!')
- resolve()
- }, 500)
- })
- }
- let sayWhatsUp = () => {
- return new Promise((resolve) => {
- setTimeout(() => {
- console.log('2. whats up?')
- resolve()
- }, 500)
- })
- }
- let sayBye = () => {
- return new Promise((resolve) => {
- setTimeout(() => {
- console.log('3. Bye all...')
- resolve()
- }, 500)
- })
- }
- sayHello()
- .then(sayWhatsUp)
- .then(sayBye)
- // albo zapis z await
- await sayHello()
- await sayWhatsUp()
- await sayBye()
- console.log('end...')
- // await musi byc zawsze w asynchronicznej funckcji, bo
- // najlepiej spakować to do funkcji async bo innaczej zamrazamy inie linie kodu.
- // tak wiec tylko te trzy linijki kodu z await czekaja
- async function myAsyncFunctions() {
- await sayHello()
- await sayWhatsUp()
- await sayBye()
- }
- myAsyncFunctions()
Advertisement
Add Comment
Please, Sign In to add comment