@@ -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
@@ -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
6870module . exports = Preprocessor ;
0 commit comments