                 // Fetch and release the future
                 futureResult = Result { try block(db) }
                 futureSemaphore.signal()
-                
             }
         } catch {
             return Future { throw error }

        var futureResult: Result<T>? = nil
        
        do {
            let (reader, release) = try readerPool.get()
            reader.async { db in
                defer {
                    try? db.commit() // Ignore commit error
                    release()
                }
                do {
                    try db.beginSnapshotIsolation()
                } catch {
                    // Snapshot isolation failure
                    futureResult = .failure(error)
                    isolationSemaphore.signal()
                    futureSemaphore.signal()

        // isolation has been established:
        let semaphore = DispatchSemaphore(value: 0)
        
        var snapshotIsolationError: Error? = nil
        let (reader, releaseReader) = try readerPool.get()
        reader.async { db in
            defer {
                _ = try? db.commit() // Ignore commit error
                releaseReader()
            }
            do {
                try db.beginSnapshotIsolation()
            } catch {
                snapshotIsolationError = error
                semaphore.signal() // Release the writer queue and rethrow error
                return
            }
