<commit_before>/* eslint no-loop-func: 1 */

var phantom = require('phantom');
var explorer = require('./explorer');

exports = module.exports = Clairvoyance;

function Clairvoyance(options) {
  this.css = options.css;
  this.html = options.html;
  this.reporters = options.reporters || [];
  this.result = {};
}

Clairvoyance.prototype.run = function(cb) {
  if (cb) {
    this.reporters.push(cb);
  }

  var cssFiles = explorer.findCssFiles(this.css);
  var htmlFiles = explorer.findHtmlFiles(this.html);

  var _this = this;
  var tasks = [];
  phantom.create(function(ph) {
    for (var html of htmlFiles) {
      for (var css of cssFiles) {
        tasks.push(html.findCss(ph, css));
      }
    }

    Promise.all(tasks).then(function() {
      ph.exit();

      for (var css of cssFiles) {
        _this.result[css.path] = css.result;
      }

      for (var reporter of _this.reporters) {
        reporter(_this.result);
      }
    });
  }, {dnodeOpts: {weak: false}});
};<commit_msg>Wrap methods for the change to async<commit_after>/* eslint no-loop-func: 1 */

var phantom = require('phantom');
var explorer = require('./explorer');

exports = module.exports = Clairvoyance;

function Clairvoyance(options) {
  this.css = options.css;
  this.html = options.html;
  this.reporters = options.reporters || [];
  this.result = {};
}

Clairvoyance.prototype.run = function(cb) {
  if (cb) {
    this.reporters.push(cb);
  }

  var _this = this;
  Promise
    .all([_createPhantom(this), _findCssFiles(this), _findHtmlFiles(this)])
    .then(function() {
      var tasks = [];

      for (var html of _this.htmlFiles) {
        for (var css of _this.cssFiles) {
          tasks.push(html.findCss(_this.ph, css));
        }
      }

      Promise.all(tasks).then(function() {
        _this.ph.exit();

        for (var css of _this.cssFiles) {
          _this.result[css.path] = css.result;
        }

        for (var reporter of _this.reporters) {
          reporter(_this.result);
        }
      });
    });
};

function _createPhantom(_this) {
  return new Promise(function(resolve) {
    phantom.create(function(ph) {
      _this.ph = ph;
      resolve();
    }, {dnodeOpts: {weak: false}});
  });
}

function _findCssFiles(_this) {
  return new Promise(function(resolve) {
    _this.cssFiles = explorer.findCssFiles(_this.css);
    resolve();
  });
}

function _findHtmlFiles(_this) {
  return new Promise(function(resolve) {
    _this.htmlFiles = explorer.findHtmlFiles(_this.html);
    resolve();
  });
}
{'fraction_non_alphanumeric': 0.15131056393963463, 'fraction_numerical': 0.0007942811755361397, 'mean_word_length': 2.8282674772036476, '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': '2714632', 'n_tokens_mistral': 884, 'n_tokens_neox': 849, 'n_words': 167}