Skip to content

Commit a193d7c

Browse files
committed
Merge pull request #98 from SparkartGroupInc/96-reload-preprocessors-in-dev
reload workers when preprocessors change
2 parents cf8fd0d + 47bd114 commit a193d7c

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

lib/preprocessor.js

+19-17
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ var EventEmitter = require('events').EventEmitter;
77

88
var _ = require('underscore');
99
var workerFarm = require('worker-farm');
10-
var workers = workerFarm({
11-
maxCallsPerWorker: 100,
12-
maxConcurrentWorkers: 4,
13-
maxConcurrentCallsPerWorker: -1,
14-
maxCallTime: 1000
15-
}, require.resolve('./preprocessor_worker.js'));
10+
11+
var workers;
1612

1713
var Preprocessor = function( preprocessor_path, options ){
1814

@@ -48,21 +44,27 @@ var Preprocessor = function( preprocessor_path, options ){
4844

4945
};
5046

51-
// update the source of the preprocessor
52-
this.updateSource = function( callback ){
53-
54-
delete require.cache[this.path];
55-
callback();
47+
};
5648

57-
};
49+
// properly inherit from EventEmitter part 2
50+
util.inherits( Preprocessor, EventEmitter );
5851

59-
this.updateSource( function(){
60-
preprocessor.emit( 'ready' );
61-
});
52+
Preprocessor.setWorkers = function(){
53+
workers = workerFarm({
54+
maxCallsPerWorker: 100,
55+
maxConcurrentWorkers: 4,
56+
maxConcurrentCallsPerWorker: -1,
57+
maxCallTime: 1000
58+
}, require.resolve('./preprocessor_worker.js'));
59+
};
6260

61+
// destroy and re-initialize worker farm
62+
// this is used to update preprocessor modules in development
63+
Preprocessor.resetWorkers = function(){
64+
workerFarm.end( workers );
65+
Preprocessor.setWorkers();
6366
};
6467

65-
// properly inherit from EventEmitter part 2
66-
util.inherits( Preprocessor, EventEmitter );
68+
Preprocessor.setWorkers();
6769

6870
module.exports = Preprocessor;

lib/server.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ var SolidusServer = function( options ){
239239
// updates the source of a preprocessor
240240
this.updatePreprocessor = function( preprocessor_path ){
241241

242-
var path_to = path.relative( paths.preprocessors, preprocessor_path );
243-
preprocessors[path_to].updateSource();
242+
Preprocessor.resetWorkers();
244243

245244
};
246245

0 commit comments

Comments
 (0)