<commit_before># Quick Overview

StopGo was created at Wistia as a way to delay actions until a condition is
met.

It's used in nearly every function of the Player API, and whenever a video is
uploaded to Wistia. At this point, it's definitely been battle tested.

Here's a very artificial example:

    var ready = new StopGo();

    // Queues the function for later because ready() is false.
    ready(function() {
      console.log("Ready, sir!");
    });

    // Prints "Ready, sir!" as soon as ready(true) is called.
    setTimeout(function() {
      ready(true);
    }, 1000);

    // Prints "Right away!" because ready() is already true.
    setTimeout(function() {
      ready(function() {
        console.log("Right away!");
      });
    }, 2000);

Now let's say you need data from two different sources before executing a 
method.

You could execute them serially (slow, can't do two things at once, not
reusable):

    getDataFromX(function() {
      getDataFromY(function() {
        console.log("Got it.");
      });
    });

You could execute them simultaneously and manage it yourself (repetitive and 
hard to manage):

    var hasDataFromX;
    function getDataFromXWrapper() {
      if (hasDataFromX) {
        if (hasDataFromY) {
          console.log("Good to go.");
        }
      } else {
        getDataFromXWrapper(function() {
          hasDataFromX = true;
          if (hasDataFromY) {
            console.log("Good to go.");
          }
        });
      }
    }

    var hasDataFromY;
    function getDataFromYWrapper() {
      if (hasDataFromY) {
        if (hasDataFromX) {
          console.log("Good to go.");
        }
      } else {
        getDataFromYWrapper(function() {
          hasDataFromY = true;
          if (hasDataFromX) {
            console.log("Good to go.");
          }
        });
      }
    }

Or you could use StopGo.

    var hasDataFromX = new StopGo();
    getDataFromX(function() {
      hasDataFromX(true);
    });

    var hasDataFromY = new StopGo();
    getDataFromY(function() {
      hasDataFromY(true);
    });

    StopGo.when(hasDataFromX, hasDataFromY, function() {
      console.log("Good to go!");<commit_msg>Correct README example with `StopGo.when`.<commit_after># Quick Overview

StopGo was created at Wistia as a way to delay actions until a condition is
met.

It's used in nearly every function of the Player API, and whenever a video is
uploaded to Wistia. At this point, it's definitely been battle tested.

Here's a very artificial example:

    var ready = new StopGo();

    // Queues the function for later because ready() is false.
    ready(function() {
      console.log("Ready, sir!");
    });

    // Prints "Ready, sir!" as soon as ready(true) is called.
    setTimeout(function() {
      ready(true);
    }, 1000);

    // Prints "Right away!" because ready() is already true.
    setTimeout(function() {
      ready(function() {
        console.log("Right away!");
      });
    }, 2000);

Now let's say you need data from two different sources before executing a 
method.

You could execute them serially (slow, can't do two things at once, not
reusable):

    getDataFromX(function() {
      getDataFromY(function() {
        console.log("Got it.");
      });
    });

You could execute them simultaneously and manage it yourself (repetitive and 
hard to manage):

    var hasDataFromX;
    function getDataFromXWrapper() {
      if (hasDataFromX) {
        if (hasDataFromY) {
          console.log("Good to go.");
        }
      } else {
        getDataFromXWrapper(function() {
          hasDataFromX = true;
          if (hasDataFromY) {
            console.log("Good to go.");
          }
        });
      }
    }

    var hasDataFromY;
    function getDataFromYWrapper() {
      if (hasDataFromY) {
        if (hasDataFromX) {
          console.log("Good to go.");
        }
      } else {
        getDataFromYWrapper(function() {
          hasDataFromY = true;
          if (hasDataFromX) {
            console.log("Good to go.");
          }
        });
      }
    }

Or you could use StopGo.

    var hasDataFromX = new StopGo();
    getDataFromX(function() {
      hasDataFromX(true);
    });

    var hasDataFromY = new StopGo();
    getDataFromY(function() {
      hasDataFromY(true);
    });

    StopGo.when(hasDataFromX, hasDataFromY).run(function() {
      console.log("Good to go!");
{'fraction_non_alphanumeric': 0.11325904025471913, 'fraction_numerical': 0.003638844666818285, 'mean_word_length': 2.269888475836431, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7601279', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1282, 'n_words': 402}