JSFiddle - React, Tailwind, and code Playground

How to turn function into promise?

by Hugo Carneiro

JavaScript

// How can we turn the following function into a promise?

var timeout;

function check() {
  if (timeout) {
    clearTimeout(timeout);
    timeout = null;
  }

  if (foobar) {
    timeout = setTimeout(function () {
      check();
    }, 100);

    return;
  }

  // Clear to do some other stuff

  // After this part I would like to resolve the Promise
}