Skip to content

Commit

Permalink
Introduce a queue such that a Node thread is available for fs tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
jorrit committed Jul 29, 2015
1 parent 3ae649b commit 19a54ce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var sass = require('node-sass');
var path = require('path');
var os = require('os');
var fs = require('fs');
var async = require('async');

// A typical sass error looks like this
var SassError = {
Expand All @@ -16,6 +17,12 @@ var SassError = {
};
var resolveError = /Cannot resolve/;

// This queue makes sure node-sass leaves one thread available for executing
// fs tasks when running the custom importer code.
// This can be removed as soon as node-sass implements a fix for this.
var threadPoolSize = process.env.UV_THREADPOOL_SIZE || 4;
var asyncSassJobQueue = async.queue(sass.render, threadPoolSize - 1);

/**
* The sass-loader makes node-sass available to webpack modules.
*
Expand Down Expand Up @@ -155,7 +162,8 @@ module.exports = function (content) {
throw err;
}
}
sass.render(opt, function onRender(err, result) {

asyncSassJobQueue.push(opt, function onRender(err, result) {
if (err) {
formatSassError(err);
callback(err);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"node-sass": "^3.1.0"
},
"dependencies": {
"async": "^1.4.0",
"loader-utils": "^0.2.5"
},
"devDependencies": {
Expand Down

0 comments on commit 19a54ce

Please sign in to comment.