Тёмный

How to make a sleep function in JavaScript with async await 

Coding With Adam
Подписаться 12 тыс.
Просмотров 10 тыс.
50% 1

In this video I’m going to show you how you can add a sleep function in JavaScript. Languages like .net, python and java have a method called sleep. This allows a method to pause and wait for a certain amount of time and then continue execution of its code. JavaScript does provide a setTimeout method where you can pass a function to execute after a certain amount of time. However with the addition of async and await in javascript we can write this solution in a more elegant way.
This is the solution used in the video:
Angle brackets are not allowed in the youtube description make sure to add it in the arrow function below
async function sleep(seconds) {
return new Promise((resolve) =rightAngleBracketHere setTimeout(resolve, seconds * 1000));
}

Опубликовано:

 

29 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 17   
Далее
Tips For Using Async/Await in JavaScript
16:26
Просмотров 395 тыс.
Sleep - Leetcode 2621 - JavaScript 30-Day Challenge
19:13
КАК БОМЖУ ЗАРАБОТАТЬ НА ТАЧКУ
1:36:32
JavaScript Pro Tips - Code This, NOT That
12:37
Просмотров 2,5 млн
Exercises: Async / Await - Javascript In Depth
56:43
Просмотров 3,6 тыс.
FizzBuzz: One Simple Interview Question
7:18
Просмотров 3,5 млн
The Async Await Episode I Promised
12:04
Просмотров 1,1 млн
JavaScript Functions Crash Course
1:36:54
Просмотров 176 тыс.
Why Signals Are Better Than React Hooks
16:30
Просмотров 478 тыс.
КАК БОМЖУ ЗАРАБОТАТЬ НА ТАЧКУ
1:36:32