<commit_before>'use strict';

var delay = require('./delay');
var attempt = require('./attempt');

function whilst(conditionFn, fn, options) {
    return attempt(conditionFn).then(function (condition) {
        return condition && Promise.resolve(fn())
        // Even if delay is 0, we always do a setTimeout in order to let the event loop breathe.
        .then(delay(options.delay))
        .then(function () {
            return whilst(conditionFn, fn, options);
        });
    });
}

/*
 * Whilst the `conditionFn` returns true, execute `fn`.
 * `fn` and `conditionFn` can return a value or a promise.
 * Delay in between iterations can be configured with `options.delay` (default is 0).
 */
module.exports = function (conditionFn, fn, options) {
    options = options || { delay: 0 };

    return whilst(conditionFn, fn, options);
};<commit_msg>update promise/whilist — lint, es6<commit_after>'use strict'

var delay = require('./delay')
var attempt = require('./attempt')

/*
  Whilst the `conditionFn` returns true, execute `fn`.
  `fn` and `conditionFn` can return a value or a promise.
  Delay in between iterations can be configured with `options.delay` (default is 0).

*/

module.exports = function whilst (conditionFn, fn, options) {
  options = options || {delay: 0}

  return attempt(conditionFn).then((condition) => {
    return condition && Promise.resolve(fn())
      // Even if delay is 0, we always do a setTimeout in order to let the event loop breathe.
      .then(delay(options.delay))
      .then(() => whilst(conditionFn, fn, options))
  })
}
{'fraction_non_alphanumeric': 0.13320586360739325, 'fraction_numerical': 0.004461440407903123, 'mean_word_length': 3.4350282485875705, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7563311', 'n_tokens_mistral': 449, 'n_tokens_neox': 436, 'n_words': 163}