Get started with q.js CDN

MIT licensed

Q.js: Library for writing async JS with deferred, promised objects.

Tags:
  • q
  • promise
  • promises
  • promises-a
  • promises-a-plus
  • deferred
  • future
  • async
  • flow control
  • fluent
  • browser
  • node

Stable version

Copied!

How to start using q.js CDN


<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.cdnhub.io/q.js/1.5.1/q.min.js"></script>
  <title>Get started with q.js CDN - cdnhub.io</title>
</head>
<body>
  <button id="promiseButton">Click me</button>

  <script>
    const promiseButton = document.getElementById('promiseButton');

    promiseButton.addEventListener('click', () => {
      const deferred = Q.defer();

      // Simulate an asynchronous operation
      setTimeout(() => {
        const result = Math.random();
        deferred.resolve(result);
      }, 1000);

      // Get the promise and handle its result
      const promise = deferred.promise;
      promise.then((value) => {
        console.log(`Random number: ${value}`);
      });
    });
  </script>
</body>
</html>
Copied!
Copied!
Copied!

All versions