<commit_before>_pool = {}
_setup = null
_extend = null
currentFlavour = null

# Helpers to manage the calls to functions defined from the start
# event if they are not available
createPool = (name)->
  _pool[name]  = {} unless _pool[name]
  _p = _pool[name]
  (evt, params)->
    _p[evt] ?= []
    _p[evt].push params
deletePool = (name)->
  delete _pool[name]

preInit = (config, cb, errb)->
  throw 'Hull.init has already been called' if _setup

  # Prepare config
  config.namespace = 'hull'
  config.debug = config.debug && { enable: true }

  _setup = 
    config: config
    userSuccessFn: cb or ->
    userFailureFn: errb or ->

  bootstrap()

_hull = window.Hull =
  on:      createPool('events')
  track:   createPool('tracks')
  init:    preInit


# Wraps the success callback
# * Extends the global object
# * Reinjects events in the live app from the pool
# * Replays the track events
successCb = (args...)->
  extension = currentFlavour.success(args...)
  _hull = window.Hull = _extend(_hull, extension)
  # Prune callback queue
  for evt, cbArray of _pool['events']
    for cb of cbArray
      _hull.events.on evt, cb
  deletePool('events')

  # Prune init queue
  _setup.userSuccessFn(_hull)

  booted.track(evt, params) for evt, param of _pool['tracks']
  deletePool('tracks')

  _hull

# Wraps the failure callback
# * Executes the failure behaviour defined by the current flavour
failureCb = (args...)->
  currentFlavour.failure(args...)
  _setup.userFailureFn(args...)

bootstrap = ()->
  return unless _setup and currentFlavour
  currentFlavour.condition(_setup.config).then(successCb, failureCb)

require ['flavour', 'underscore', 'lib/utils/version'], (flavour, _, version)->
  _hull.version = version
  _extend = _.extend
  currentFlavour = flavour
  bootstrap()
<commit_msg>Uses lock<commit_after>_setup = null
_extend = null
currentFlavour = null


createLock = (locks, openDoorFn)->
  _locks = [].concat locks
  (lock)->
    index = _locks.indexOf lock
    openDoorFn() if !!~index and _locks.splice(index, 1).length and !_locks.length


# Helpers to manage the calls to functions defined from the start
# event if they are not available
_pool = {}
createPool = (name)->
  _pool[name]  = {} unless _pool[name]
  _p = _pool[name]
  (evt, params)->
    _p[evt] ?= []
    _p[evt].push params
deletePool = (name)->
  delete _pool[name]


# * Checks that it has not been called before
# * Augments coniguration
# * Unlocks the achievement :p
preInit = (config, cb, errb)->
  throw 'Hull.init has already been called' if _setup

  # Prepare config
  config.namespace = 'hull'
  config.debug = config.debug && { enable: true }

  _setup = 
    config: config
    userSuccessFn: cb or ->
    userFailureFn: errb or ->

  bootstrapUnlock 'init'


_hull = window.Hull =
  on:      createPool('events')
  track:   createPool('tracks')
  init:    preInit


# Wraps the success callback
# * Extends the global object
# * Reinjects events in the live app from the pool
# * Replays the track events
successCb = (args...)->
  extension = currentFlavour.success(args...)
  _hull = window.Hull = _extend(_hull, extension)
  # Prune callback queue
  for evt, cbArray of _pool['events']
    for cb of cbArray
      _hull.events.on evt, cb
  deletePool('events')

  # Prune init queue
  _setup.userSuccessFn(_hull)

  booted.track(evt, params) for evt, param of _pool['tracks']
  deletePool('tracks')

  _hull


# Wraps the failure callback
# * Executes the failure behaviour defined by the current flavour
failureCb = (args...)->
  currentFlavour.failure(args...)
  _setup.userFailureFn(args...)

bootstrapUnlock = createLock ['init', 'require'], ->
  currentFlavour.condition(_setup.config).then(successCb, failureCb)

require ['flavour', 'underscore', 'lib/utils/version'], (flavour, _, version)->
  _hull.version = version
  _extend = _.extend
  currentFlavour = flavour
  bootstrapUnlock 'require'

{'fraction_non_alphanumeric': 0.12001023541453429, 'fraction_numerical': 0.00025588536335721597, 'mean_word_length': 3.6535714285714285, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '3058730', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1266, 'n_words': 381}