@@ -6,6 +6,8 @@ var temp = require("temp").track();
6
6
var loaderUtils = require ( "loader-utils" ) ;
7
7
var elmCompiler = require ( "node-elm-compiler" ) ;
8
8
9
+ var runningInstances = 0 ;
10
+
9
11
var getFiles = function ( options ) {
10
12
var files = options && options . files ;
11
13
@@ -95,6 +97,14 @@ module.exports = function() {
95
97
var files = getFiles . call ( this , options ) ;
96
98
var resourcePath = this . resourcePath ;
97
99
100
+ var maxInstances = options . maxInstances ;
101
+
102
+ if ( typeof maxInstances === "undefined" ) {
103
+ maxInstances = null ;
104
+ } else {
105
+ delete options . maxInstances ;
106
+ }
107
+
98
108
var promises = [ ] ;
99
109
100
110
// we only need to track deps if we are in watch mode
@@ -124,30 +134,43 @@ module.exports = function() {
124
134
promises . push ( dependencies ) ;
125
135
}
126
136
127
- var compilation = compile ( files , options )
128
- . then ( function ( v ) { return { kind : "success" , result : v } ; } )
129
- . catch ( function ( v ) { return { kind : "error" , error : v } ; } ) ;
130
-
131
- promises . push ( compilation ) ;
132
-
133
- Promise . all ( promises )
134
- . then ( function ( results ) {
135
- var output = results [ results . length - 1 ] ; // compilation output is always last
137
+ var intervalId ;
138
+
139
+ var run = function ( ) {
140
+ if ( maxInstances !== null && runningInstances >= maxInstances ) { return false } ;
141
+ runningInstances += 1 ;
142
+ clearInterval ( intervalId ) ;
143
+
144
+ var compilation = compile ( files , options )
145
+ . then ( function ( v ) { runningInstances -= 1 ; return { kind : "success" , result : v } ; } )
146
+ . catch ( function ( v ) { runningInstances -= 1 ; return { kind : "error" , error : v } ; } ) ;
147
+
148
+ promises . push ( compilation ) ;
149
+
150
+ Promise . all ( promises )
151
+ . then ( function ( results ) {
152
+ var output = results [ results . length - 1 ] ; // compilation output is always last
153
+
154
+ if ( output . kind === "success" ) {
155
+ callback ( null , output . result ) ;
156
+ } else {
157
+ if ( typeof output . error === "string" ) {
158
+ output . error = new Error ( output . error ) ;
159
+ }
160
+
161
+ output . error . message = "Compiler process exited with error " + output . error . message ;
162
+ output . error . stack = null ;
163
+ callback ( output . error ) ;
164
+ }
165
+ } ) . catch ( function ( err ) {
166
+ callback ( err ) ;
167
+ } ) ;
136
168
137
- if ( output . kind === "success" ) {
138
- callback ( null , output . result ) ;
139
- } else {
140
- if ( typeof output . error === "string" ) {
141
- output . error = new Error ( output . error ) ;
142
- }
169
+ } ;
143
170
144
- output . error . message = "Compiler process exited with error " + output . error . message ;
145
- output . error . stack = null ;
146
- callback ( output . error ) ;
147
- }
148
- } ) . catch ( function ( err ) {
149
- callback ( err ) ;
150
- } ) ;
171
+ if ( run ( ) === false ) {
172
+ intervalId = setInterval ( run , 200 ) ;
173
+ }
151
174
}
152
175
153
176
0 commit comments