<commit_before>import { sum, isFunction } from 'lodash'

function progressAdapterFactory (onProgressCallback) {
  const iface = {}
  const handlers = []

  function propagateProgress () {
    const progress = sum(handlers) / handlers.length
    onProgressCallback({
      complete: Math.max(0, Math.min(100, progress)),
      jobCount: handlers.length
    })
  }

  iface.createHandler = () => {
    const id = handlers.length
    handlers[id] = 0
    return progress => {
      if (progress.lengthComputable) {
        handlers[id] = progress.loaded / progress.total * 100
        propagateProgress()
      }
    }
  }

  return iface
}

async function allSettled (promises) {
  if (Promise.allSettled) {
    return Promise.allSettled(promises)
  } else {
    const allSettled = await import('promise.allsettled').then(m => m.default)
    return allSettled(promises)
  }
}

function selectResolver (spec) {
  switch (true) {
    case spec === 'all':
      return Promise.all
    case spec === 'allSettled':
      return allSettled
    case isFunction(spec):<commit_msg>unbound Promise.all cannot be passed as callback<commit_after>import { sum, isFunction } from 'lodash'

function progressAdapterFactory (onProgressCallback) {
  const iface = {}
  const handlers = []

  function propagateProgress () {
    const progress = sum(handlers) / handlers.length
    onProgressCallback({
      complete: Math.max(0, Math.min(100, progress)),
      jobCount: handlers.length
    })
  }

  iface.createHandler = () => {
    const id = handlers.length
    handlers[id] = 0
    return progress => {
      if (progress.lengthComputable) {
        handlers[id] = progress.loaded / progress.total * 100
        propagateProgress()
      }
    }
  }

  return iface
}

async function allSettled (promises) {
  if (Promise.allSettled) {
    return Promise.allSettled(promises)
  } else {
    const allSettled = await import('promise.allsettled').then(m => m.default)
    return allSettled(promises)
  }
}

function selectResolver (spec) {
  switch (true) {
    case spec === 'all':
      return promises => Promise.all(promises)
    case spec === 'allSettled':
      return allSettled
    case isFunction(spec):
{'fraction_non_alphanumeric': 0.11515703231679562, 'fraction_numerical': 0.007282658170232135, 'mean_word_length': 3.0855018587360594, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '4002999', 'n_tokens_mistral': 706, 'n_tokens_neox': 673, 'n_words': 157}