@@ -132,26 +132,32 @@ async function _export({
132
132
if ( seen . has ( pathname ) ) return ;
133
133
seen . add ( pathname ) ;
134
134
135
- const timeout_deferred = new Deferred ( ) ;
136
- const the_timeout = setTimeout ( ( ) => {
137
- timeout_deferred . reject ( new Error ( `Timed out waiting for ${ url . href } ` ) ) ;
138
- } , timeout ) ;
135
+ const r = await q . add ( async ( ) => {
136
+ const timeout_deferred = new Deferred ( ) ;
137
+ const the_timeout = setTimeout ( ( ) => {
138
+ timeout_deferred . reject ( new Error ( `Timed out waiting for ${ url . href } ` ) ) ;
139
+ } , timeout ) ;
139
140
140
- const r = await Promise . race ( [
141
- q . add ( ( ) => fetch ( url . href , {
142
- redirect : 'manual'
143
- } ) ) ,
144
- timeout_deferred . promise
145
- ] ) ;
141
+ const r = await Promise . race ( [
142
+ fetch ( url . href , {
143
+ redirect : 'manual'
144
+ } ) ,
145
+ timeout_deferred . promise
146
+ ] ) ;
146
147
147
- clearTimeout ( the_timeout ) ; // prevent it hanging at the end
148
+ clearTimeout ( the_timeout ) ; // prevent it hanging at the end
149
+
150
+ return r ;
151
+ } ) as Response ;
148
152
149
153
let type = r . headers . get ( 'Content-Type' ) ;
150
154
151
155
let body = await r . text ( ) ;
152
156
153
157
const range = ~ ~ ( r . status / 100 ) ;
154
158
159
+ let last_task ;
160
+
155
161
if ( range === 2 ) {
156
162
if ( type === 'text/html' ) {
157
163
// parse link rel=preload headers and embed them in the HTML
@@ -173,8 +179,6 @@ async function _export({
173
179
let match ;
174
180
let pattern = / < a ( [ \s \S ] + ?) > / gm;
175
181
176
- let promise ;
177
-
178
182
while ( match = pattern . exec ( cleaned ) ) {
179
183
const attrs = match [ 1 ] ;
180
184
const href = get_href ( attrs ) ;
@@ -183,12 +187,10 @@ async function _export({
183
187
const url = resolve ( base . href , href ) ;
184
188
185
189
if ( url . protocol === protocol && url . host === host ) {
186
- promise = handle ( url ) ;
190
+ last_task = handle ( url ) ;
187
191
}
188
192
}
189
193
}
190
-
191
- await promise ;
192
194
}
193
195
}
194
196
}
@@ -199,10 +201,12 @@ async function _export({
199
201
type = 'text/html' ;
200
202
body = `<script>window.location.href = "${ location . replace ( origin , '' ) } "</script>` ;
201
203
202
- await handle ( resolve ( root . href , location ) ) ;
204
+ last_task = handle ( resolve ( root . href , location ) ) ;
203
205
}
204
206
205
207
save ( pathname , r . status , type , body ) ;
208
+
209
+ await last_task ;
206
210
}
207
211
208
212
try {
0 commit comments