 
 module.exports = class Bongo extends EventEmitter
   [READY, NOTREADY] = [0,1]
+
+  Promise = require 'bluebird'
+
   # core
   url = require 'url'
-  fs = require 'fs'
+  fs = Promise.promisifyAll require 'fs'
   nodePath = require 'path'
 
   require 'colors'

        if newName in names
          JsPath.setAt def, path.concat(names.indexOf newName), newModel

  listModels=(root="", modelPath, acc={})->
    path = nodePath.join root, modelPath
    stat = fs.statSync path
    if stat.isDirectory()
      names = fs.readdirSync path
      for name in names
        listModels root, nodePath.join(modelPath, name), acc
    else if /(\.coffee|\.js)$/.test path
      acc[path] = NOTREADY
    return acc

  createModelRegistry:(modelPath)->
    acc = {}
    if Array.isArray modelPath
      listModels @root, item, acc  for item in modelPath
    else
      listModels @root, modelPath, acc
    new ModelRegistry acc

  loadModels: (modelPath) ->
    @registry = @createModelRegistry(modelPath)
    @registry.forEach (path) =>
      try model = require path
      catch e
        console.error e
        err = new Error
        err.originalError = e
        err.message = "Error loading a class: #{path}"
        return @emit 'error', err
      if model.name? and ('function' is typeof model)
        @defineModel model.name, model
      else
        @defineModel name, konstructor  for own name, konstructor of model
      @registry.setState path, READY
    @emit 'ready'

  getInstanceRoutingKey =(inst, event)->
    "oid.#{inst.getId()}.event.#{event}"

  {extend}        = require 'underscore'
  @JsPath = JsPath = require 'jspath'
  @Inflector      = require 'inflector'

  # lib
  # the base klass of the library:
  @Base = Base    = require './base'
