@@ -7,12 +7,8 @@ var EventEmitter = require('events').EventEmitter;
7
7
8
8
var _ = require ( 'underscore' ) ;
9
9
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 ;
16
12
17
13
var Preprocessor = function ( preprocessor_path , options ) {
18
14
@@ -48,21 +44,27 @@ var Preprocessor = function( preprocessor_path, options ){
48
44
49
45
} ;
50
46
51
- // update the source of the preprocessor
52
- this . updateSource = function ( callback ) {
53
-
54
- delete require . cache [ this . path ] ;
55
- callback ( ) ;
47
+ } ;
56
48
57
- } ;
49
+ // properly inherit from EventEmitter part 2
50
+ util . inherits ( Preprocessor , EventEmitter ) ;
58
51
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
+ } ;
62
60
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 ( ) ;
63
66
} ;
64
67
65
- // properly inherit from EventEmitter part 2
66
- util . inherits ( Preprocessor , EventEmitter ) ;
68
+ Preprocessor . setWorkers ( ) ;
67
69
68
70
module . exports = Preprocessor ;
0 commit comments