Skip to content

Commit 47bd114

Browse files
committed
reload workers when preprocessors change
1 parent 7910117 commit 47bd114

2 files changed

Lines changed: 20 additions & 19 deletions

File tree

lib/preprocessor.js

Lines changed: 19 additions & 17 deletions
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

@@ -38,21 +34,27 @@ var Preprocessor = function( preprocessor_path, options ){
3834

3935
};
4036

41-
// update the source of the preprocessor
42-
this.updateSource = function( callback ){
43-
44-
delete require.cache[this.path];
45-
callback();
37+
};
4638

47-
};
39+
// properly inherit from EventEmitter part 2
40+
util.inherits( Preprocessor, EventEmitter );
4841

49-
this.updateSource( function(){
50-
preprocessor.emit( 'ready' );
51-
});
42+
Preprocessor.setWorkers = function(){
43+
workers = workerFarm({
44+
maxCallsPerWorker: 100,
45+
maxConcurrentWorkers: 4,
46+
maxConcurrentCallsPerWorker: -1,
47+
maxCallTime: 1000
48+
}, require.resolve('./preprocessor_worker.js'));
49+
};
5250

51+
// destroy and re-initialize worker farm
52+
// this is used to update preprocessor modules in development
53+
Preprocessor.resetWorkers = function(){
54+
workerFarm.end( workers );
55+
Preprocessor.setWorkers();
5356
};
5457

55-
// properly inherit from EventEmitter part 2
56-
util.inherits( Preprocessor, EventEmitter );
58+
Preprocessor.setWorkers();
5759

5860
module.exports = Preprocessor;

lib/server.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,7 @@ var SolidusServer = function( options ){
227227
// updates the source of a preprocessor
228228
this.updatePreprocessor = function( preprocessor_path ){
229229

230-
var path_to = path.relative( paths.preprocessors, preprocessor_path );
231-
preprocessors[path_to].updateSource();
230+
Preprocessor.resetWorkers();
232231

233232
};
234233

0 commit comments

Comments
 (0)