 withSerializer = (type, serializer) ->
   _with 'Serializer', type, serializers, serializer
 
-loadBuiltin  = (builtinNames,tab,type) ->  
+loadBuiltin  = (builtinNames,array,type) ->  
   _.pairs(builtinNames).forEach (pair) ->
     name = pair[1]
-    tab[name]=require "./#{type}/#{name}"
-
-
+    array[name]=require "./#{type}/#{name}"
 
 loadCustom = (pathToLoad,fn) ->
-  walk pathToLoad, (err,results) ->
-    throw err if err
-    _(results).each (file) ->
-      ext = path.extname(file)
-      if ext is ".js" or ext is ".node" or ext is ".json"
-        # TODO : Error or Warning 
-        logger.warn "File #{file} will override the .coffee version" 
-      return if path.extname(file) isnt ".coffee"
-      fn path.basename(file,".coffee"),file 
+  results = walkSync pathToLoad
+  console.log results
+  _(results).each (file) ->
+    ext = path.extname(file)
+    return if ext isnt ".coffee"
 
-walk = (dir, done) -> 
+    # Built the relative name 
+    # actors/tools/myActor.coffe 
+    # => type : tools/myActor
+    relative = path.relative(pathToLoad,file)
+    type = relative.match(/(.+)\.coffee$/)[1]
+    fn type,file 
+
+walkSync = (dir) ->
   logger.info "Loading #{dir}"
   results = [];
-  fs.readdir dir, (err, list) ->
-    return done(err) if err
-    i = 0;
-    next = () ->
-      file = list[i++];
-      return done(null, results) if not file
-      file = dir + '/' + file;
-      fs.stat file, (err, stat) ->
-        if (stat and stat.isDirectory())
-          walk file, (err, res) ->
-            results = results.concat(res);
-            next();
-        else
-          results.push(file);
-          next();
-    next()
+  list = fs.readdirSync dir
+  _(list).each (file) ->
+    file = dir + '/' + file
+    stat = fs.statSync(file)
+    if (stat and stat.isDirectory())
+      results=results.concat(walkSync(file))
+    else
+      results.push(file)
+  return results
+
 
 loadBuiltin builtinActorNames,actors,"actor"
 loadBuiltin builtinAdapterNames,adapters,"adapters"

loadCustom "#{process.cwd()}/adapters", withAdapter
loadCustom "#{process.cwd()}/serializers", withSerializer

_new = (type, tab, properties) ->
  throw new Error "type undefined" if not type
  if not tab[type]
    tab[type] = require type
  else 
    if typeof tab[type] is "string"   
      tab[type] = require tab[type]
  new tab[type] properties

newActor = (type, properties) ->
  _new type, actors, properties


exports.newActor = newActor
exports.newAdapter = newAdapter
exports.newSerializer = newSerializer
