From 0db61c3f5483b3475d6b1c3d9b1780eb745fb7f5 Mon Sep 17 00:00:00 2001 From: Ricardo Tomasi Date: Fri, 5 Apr 2013 21:42:53 -0300 Subject: [PATCH] Use simple async queue instead of promises --- flour.coffee | 23 +++++++++++------------ package.json | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/flour.coffee b/flour.coffee index b03d86d..389591f 100644 --- a/flour.coffee +++ b/flour.coffee @@ -4,13 +4,14 @@ util = require 'util' domain = require 'domain' colors = require 'colors' glob = require 'glob' -Q = require 'q' +queue = require 'queue-async' File = require './lib/file' logger = require './lib/logger' ERROR = require './lib/errors' isWild = (str) -> /[*!{}|}]/.test str +asyncMap = (q, fn, items) -> q.defer(fn, item) for item in items; q # Main object / API flour = @@ -83,17 +84,15 @@ flour = return # Get a list of files from a wildcard path (*.ext) - getFiles: (pattern, cb) -> - try pattern = path.join pattern, '*' if (fs.statSync pattern).isDirectory() - defer = Q.defer() - if Array.isArray pattern - searches = pattern.map (path) -> flour.getFiles path - Q.all(searches).then (searches) -> - defer.resolve searches.reduce (l, r) -> l.concat r, [] - else - glob pattern, (er, files) -> defer.resolve files - defer.promise.done (files) -> cb files if cb? - defer.promise + getFiles: (patterns, cb) -> + paths = [].concat(patterns) + asyncMap(queue(), fs.stat, paths).awaitAll (err, stats) -> + if stats then paths = stats.map (stat, i) -> + path.join(paths[i], '*' if stat.isDirectory()) + + asyncMap(queue(), glob, paths).awaitAll (err, files) -> + cb Array::concat.apply [], files + # Get file(s)' contents get: (filepath, cb) -> diff --git a/package.json b/package.json index 9ebc27a..84a5f9d 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "colors": "*", "hound": "*", "glob": "*", - "q": "*" + "queue-async": "~1" }, "devDependencies": { "mocha": "*",