• Home
  • Explore

How to implement a promise-based API - Learn web development | MDN

developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Implementing_a_promise-based_API

2 Users

0 Comments

9 Highlights

0 Notes

Tags

ProgrammingJavaScript

Top Highlights

  • The setTimeout() API takes as arguments a callback function and a delay, given in milliseconds. When setTimeout() is called, it starts a timer set to the given delay, and when the time expires, it calls the given function

  • The key component here is the Promise() constructor. The Promise() constructor takes a single function as an argument. We'll call this function the executor. When you create a new promise you supply the implementation of the executor.

  • This executor function itself takes two arguments, which are both also functions, and which are conventionally called resolve and reject

  • How to implement a promise-based API

  • Implementing an alarm() API

  • Wrapping setTimeout()

  • The Promise() constructor

  • Using the alarm() API

  • Using async and await with the alarm() API

Ready to highlight and find good content?

Glasp is a social web highlighter that people can highlight and organize quotes and thoughts from the web, and access other like-minded people’s learning.

AboutPrivacyTerms

© 2023 Glasp Inc. All rights reserved.