@@ -330,22 +330,14 @@ extension DatabasePool: DatabaseReader {
330
330
}
331
331
332
332
public func asyncRead( _ value: @escaping ( Result < Database , Error > ) -> Void ) {
333
- // First async jump in order to grab a reader connection.
334
- // Honor configuration dispatching (qos/targetQueue).
335
- let label = configuration. identifier (
336
- defaultLabel: " GRDB.DatabasePool " ,
337
- purpose: " asyncRead " )
338
- configuration
339
- . makeReaderDispatchQueue ( label: label)
340
- . async {
333
+ do {
334
+ guard let readerPool = self . readerPool else {
335
+ throw DatabaseError ( resultCode: . SQLITE_MISUSE, message: " Connection is closed " )
336
+ }
337
+ readerPool. async { result in
341
338
do {
342
- guard let readerPool = self . readerPool else {
343
- throw DatabaseError . connectionIsClosed ( )
344
- }
345
- let ( reader, releaseReader) = try readerPool. get ( )
346
-
347
- // Second async jump because sync could deadlock if
348
- // configuration has a serial targetQueue.
339
+ let ( reader, releaseReader) = try result. get ( )
340
+ // Second async jump because that's how `Pool.async` has to be used.
349
341
reader. async { db in
350
342
defer {
351
343
try ? db. commit ( ) // Ignore commit error
@@ -364,6 +356,9 @@ extension DatabasePool: DatabaseReader {
364
356
value ( . failure( error) )
365
357
}
366
358
}
359
+ } catch {
360
+ value ( . failure( error) )
361
+ }
367
362
}
368
363
369
364
@_disfavoredOverload // SR-15150 Async overloading in protocol implementation fails
@@ -381,22 +376,14 @@ extension DatabasePool: DatabaseReader {
381
376
}
382
377
383
378
public func asyncUnsafeRead( _ value: @escaping ( Result < Database , Error > ) -> Void ) {
384
- // First async jump in order to grab a reader connection.
385
- // Honor configuration dispatching (qos/targetQueue).
386
- let label = configuration. identifier (
387
- defaultLabel: " GRDB.DatabasePool " ,
388
- purpose: " asyncUnsafeRead " )
389
- configuration
390
- . makeReaderDispatchQueue ( label: label)
391
- . async {
379
+ do {
380
+ guard let readerPool = self . readerPool else {
381
+ throw DatabaseError ( resultCode: . SQLITE_MISUSE, message: " Connection is closed " )
382
+ }
383
+ readerPool. async { result in
392
384
do {
393
- guard let readerPool = self . readerPool else {
394
- throw DatabaseError ( resultCode: . SQLITE_MISUSE, message: " Connection is closed " )
395
- }
396
- let ( reader, releaseReader) = try readerPool. get ( )
397
-
398
- // Second async jump because sync could deadlock if
399
- // configuration has a serial targetQueue.
385
+ let ( reader, releaseReader) = try result. get ( )
386
+ // Second async jump because that's how `Pool.async` has to be used.
400
387
reader. async { db in
401
388
defer {
402
389
releaseReader ( )
@@ -413,6 +400,9 @@ extension DatabasePool: DatabaseReader {
413
400
value ( . failure( error) )
414
401
}
415
402
}
403
+ } catch {
404
+ value ( . failure( error) )
405
+ }
416
406
}
417
407
418
408
public func unsafeReentrantRead< T> ( _ value: ( Database ) throws -> T ) throws -> T {
0 commit comments