To wrap setTimeout in a promise returned by a future. We can wrap setTimeout in a promise by using the then() method to return a Promise. The then() method takes upto two arguments that are callback functions for the success and failure conditions of the Promise. This function returns a promise. There can be two different values if the function called onFulfilled that’s mean promise is fulfilled. If the function onRejected called that means promise is rejected.
Below example will illustrate the approach:
- Before Clicking the button:
- After clicking the button:
- Java Script | setTimeout() & setInterval() Method
- How to convert an existing callback to a promise in Node.js ?
- How to wait for a promise to finish before returning the variable of a function?
- CSS | flex-wrap property
- CSS | word-wrap Property
- Underscore.js | _.wrap() with Examples
- HTML | wrap Attribute
- jQuery | wrap() with Examples
- HTML | <textarea> wrap Attribute
- Wrap Around Concept and TCP Sequence Number
- HTML | DOM Textarea wrap Property
- How to wrap the text around an image using HTML and CSS ?
- How to wrap text around circular carousel in Bootstrap 4 ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.