diff --git a/native/swift/Sources/wordpress-api-cache/WordPressApiCache.swift b/native/swift/Sources/wordpress-api-cache/WordPressApiCache.swift index 8c29e73eb..33fc03ab3 100644 --- a/native/swift/Sources/wordpress-api-cache/WordPressApiCache.swift +++ b/native/swift/Sources/wordpress-api-cache/WordPressApiCache.swift @@ -1,9 +1,9 @@ import Foundation import WordPressAPIInternal -public actor WordPressApiCache { +public final class WordPressApiCache: Sendable { - private let cache: WpApiCache + public let cache: WpApiCache private let delegate: any DatabaseDelegate public struct Notifications { @@ -24,12 +24,12 @@ public actor WordPressApiCache { } /// Creates a new in-memory cache - public init(delegate: DatabaseDelegate = ApiCacheDelegate()) throws { + public convenience init(delegate: DatabaseDelegate = ApiCacheDelegate()) throws { try self.init(path: ":memory:", delegate: delegate) } /// Creates a new cache at the specified file system URL - public init(url: URL, delegate: DatabaseDelegate = ApiCacheDelegate()) throws { + public convenience init(url: URL, delegate: DatabaseDelegate = ApiCacheDelegate()) throws { try self.init(path: url.absoluteString, delegate: delegate) } @@ -39,7 +39,7 @@ public actor WordPressApiCache { self.delegate = delegate } - public func performMigrations() async throws -> Int { + public func performMigrations() throws -> Int { return Int(try self.cache.performMigrations()) } diff --git a/native/swift/Sources/wordpress-api/WordPressAPI.swift b/native/swift/Sources/wordpress-api/WordPressAPI.swift index 4a5efd3f0..cb21b87ce 100644 --- a/native/swift/Sources/wordpress-api/WordPressAPI.swift +++ b/native/swift/Sources/wordpress-api/WordPressAPI.swift @@ -9,7 +9,7 @@ import FoundationNetworking import Combine #endif -public actor WordPressAPI { +public final class WordPressAPI: Sendable { enum Errors: Error { case unableToParseResponse @@ -20,7 +20,7 @@ public actor WordPressAPI { private let apiClientDelegate: WpApiClientDelegate package let requestBuilder: UniffiWpApiClient - public init( + public convenience init( urlSession: URLSession, apiRootUrl: ParsedUrl, authentication: WpAuthentication, @@ -36,7 +36,7 @@ public actor WordPressAPI { ) } - public init( + public convenience init( urlSession: URLSession, apiRootUrl: ParsedUrl, authenticationProvider: WpAuthenticationProvider, @@ -52,7 +52,7 @@ public actor WordPressAPI { ) } - public init( + public convenience init( urlSession: URLSession, apiUrlResolver: ApiUrlResolver, authenticationProvider: WpAuthenticationProvider, @@ -68,7 +68,7 @@ public actor WordPressAPI { ) } - public init( + public convenience init( urlSession: URLSession, siteUrl: String, apiRootUrl: ParsedUrl, @@ -93,7 +93,7 @@ public actor WordPressAPI { ) } - public init( + public convenience init( urlSession: URLSession, details: AutoDiscoveryAttemptSuccess, username: String, diff --git a/native/swift/Tests/wordpress-api-cache/WordPressApiCacheTests.swift b/native/swift/Tests/wordpress-api-cache/WordPressApiCacheTests.swift index 706635d37..ae8021984 100644 --- a/native/swift/Tests/wordpress-api-cache/WordPressApiCacheTests.swift +++ b/native/swift/Tests/wordpress-api-cache/WordPressApiCacheTests.swift @@ -12,7 +12,7 @@ actor Test { } @Test func testMigrationsWork() async throws { - let migrationsPerformed = try await self.cache.performMigrations() + let migrationsPerformed = try self.cache.performMigrations() #expect(migrationsPerformed == 6) } @@ -26,11 +26,14 @@ actor Test { } } - await self.cache.startListeningForUpdates() - let migrationCount = try await self.cache.performMigrations() + // Wait for the observer Task to start running. + try await Task.sleep(nanoseconds: 100 * NSEC_PER_MSEC) + + self.cache.startListeningForUpdates() + let migrationCount = try self.cache.performMigrations() // Wait for NotificationCenter to finish delivery - try await Task.sleep(nanoseconds: 10 * NSEC_PER_MSEC) + try await Task.sleep(nanoseconds: 100 * NSEC_PER_MSEC) #expect(migrationCount == self.changeCount) handle.cancel()