@@ -7,12 +7,8 @@ var EventEmitter = require('events').EventEmitter;
77
88var _ = require ( 'underscore' ) ;
99var 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
1713var 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
5860module . exports = Preprocessor ;
0 commit comments