@@ -333,14 +333,17 @@ public final class ManifestLoader: ManifestLoaderProtocol {
333
333
)
334
334
}
335
335
336
- var closeAfterRead = DelayableAction ( target : cache ) { cache in
336
+ let closingCompletion = { ( result : Result < ManifestJSONParser . Result , Error > ) in
337
337
do {
338
- try cache. close ( )
338
+ try cache? . close ( )
339
339
} catch {
340
340
observabilityScope. emit ( warning: " failed closing cache: \( error) " )
341
341
}
342
+
343
+ callbackQueue. async {
344
+ completion ( result)
345
+ }
342
346
}
343
- defer { closeAfterRead. perform ( ) }
344
347
345
348
let key : CacheKey
346
349
do {
@@ -353,9 +356,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
353
356
fileSystem: fileSystem
354
357
)
355
358
} catch {
356
- return callbackQueue. async {
357
- completion ( . failure( error) )
358
- }
359
+ return closingCompletion ( . failure( error) )
359
360
}
360
361
361
362
do {
@@ -371,17 +372,12 @@ public final class ManifestLoader: ManifestLoaderProtocol {
371
372
fileSystem: fileSystem,
372
373
observabilityScope: observabilityScope
373
374
)
374
- return callbackQueue. async {
375
- completion ( . success( parsedManifest) )
376
- }
375
+ return closingCompletion ( . success( parsedManifest) )
377
376
}
378
377
} catch {
379
378
observabilityScope. emit ( warning: " failed loading cached manifest for ' \( key. packageIdentity) ': \( error) " )
380
379
}
381
380
382
- // delay closing cache until after write.
383
- let closeAfterWrite = closeAfterRead. delay ( )
384
-
385
381
// shells out and compiles the manifest, finally output a JSON
386
382
observabilityScope. emit ( debug: " evaluating manifest for ' \( packageIdentity) ' v. \( packageVersion? . description ?? " unknown " ) " )
387
383
do {
@@ -396,8 +392,6 @@ public final class ManifestLoader: ManifestLoaderProtocol {
396
392
dispatchPrecondition ( condition: . onQueue( callbackQueue) )
397
393
398
394
do {
399
- defer { closeAfterWrite. perform ( ) }
400
-
401
395
let evaluationResult = try result. get ( )
402
396
// only cache successfully parsed manifests
403
397
let parseManifest = try self . parseManifest (
@@ -417,17 +411,13 @@ public final class ManifestLoader: ManifestLoaderProtocol {
417
411
observabilityScope. emit ( warning: " failed storing manifest for ' \( key. packageIdentity) ' in cache: \( error) " )
418
412
}
419
413
420
- completion ( . success( parseManifest) )
414
+ return closingCompletion ( . success( parseManifest) )
421
415
} catch {
422
- callbackQueue. async {
423
- completion ( . failure( error) )
424
- }
416
+ return closingCompletion ( . failure( error) )
425
417
}
426
418
}
427
419
} catch {
428
- callbackQueue. async {
429
- completion ( . failure( error) )
430
- }
420
+ return closingCompletion ( . failure( error) )
431
421
}
432
422
}
433
423
0 commit comments