File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ class FileProcessor extends EventEmitter {
9
9
super ( ) ;
10
10
options = options || { } ;
11
11
const glob = ( this . glob = globStream ( globPattern ) ) ;
12
+ this . invokeWorker = options . invokeWorker || defaultInvokeWorker ;
12
13
const workers = ( this . workers = workerFarm ( options . worker || { } , worker ) ) ;
13
14
14
15
let allQueued = false ;
@@ -49,7 +50,7 @@ class FileProcessor extends EventEmitter {
49
50
}
50
51
51
52
process ( path , callback ) {
52
- this . workers ( path , callback ) ;
53
+ this . invokeWorker ( this . workers , path , callback ) ;
53
54
}
54
55
55
56
destroy ( callback ) {
@@ -58,4 +59,8 @@ class FileProcessor extends EventEmitter {
58
59
}
59
60
}
60
61
62
+ function defaultInvokeWorker ( workers , path , callback ) {
63
+ workers ( path , callback ) ;
64
+ }
65
+
61
66
module . exports = FileProcessor ;
Original file line number Diff line number Diff line change @@ -111,4 +111,28 @@ describe('success', () => {
111
111
} ) ;
112
112
} ) ;
113
113
} ) ;
114
+
115
+ test ( 'invokeWorker' , ( ) => {
116
+ expect . assertions ( 3 ) ;
117
+
118
+ const processor = new FileProcessor ( pattern , workerPath , {
119
+ invokeWorker ( workers , filepath , callback ) {
120
+ workers ( filepath , ( err , result ) =>
121
+ err ? callback ( err ) : callback ( null , `${ result } !` )
122
+ ) ;
123
+ } ,
124
+ } ) ;
125
+
126
+ const handler = jest . fn ( ) ;
127
+ processor . on ( 'processed' , handler ) ;
128
+
129
+ return new Promise ( ( resolve ) => {
130
+ processor . on ( 'end' , ( ) => {
131
+ expect ( handler ) . toHaveBeenCalledWith ( examplePath ( '1.txt' ) , 'a!' ) ;
132
+ expect ( handler ) . toHaveBeenCalledWith ( examplePath ( '2.txt' ) , 'b!' ) ;
133
+ expect ( handler ) . toHaveBeenCalledWith ( examplePath ( '3.txt' ) , 'c!' ) ;
134
+ resolve ( ) ;
135
+ } ) ;
136
+ } ) ;
137
+ } ) ;
114
138
} ) ;
You can’t perform that action at this time.
0 commit comments