Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions native/swift/Sources/wordpress-api-cache/WordPressApiCache.swift
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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)
}

Expand All @@ -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())
}

Expand Down
12 changes: 6 additions & 6 deletions native/swift/Sources/wordpress-api/WordPressAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import FoundationNetworking
import Combine
#endif

public actor WordPressAPI {
public final class WordPressAPI: Sendable {

enum Errors: Error {
case unableToParseResponse
Expand All @@ -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,
Expand All @@ -36,7 +36,7 @@ public actor WordPressAPI {
)
}

public init(
public convenience init(
urlSession: URLSession,
apiRootUrl: ParsedUrl,
authenticationProvider: WpAuthenticationProvider,
Expand All @@ -52,7 +52,7 @@ public actor WordPressAPI {
)
}

public init(
public convenience init(
urlSession: URLSession,
apiUrlResolver: ApiUrlResolver,
authenticationProvider: WpAuthenticationProvider,
Expand All @@ -68,7 +68,7 @@ public actor WordPressAPI {
)
}

public init(
public convenience init(
urlSession: URLSession,
siteUrl: String,
apiRootUrl: ParsedUrl,
Expand All @@ -93,7 +93,7 @@ public actor WordPressAPI {
)
}

public init(
public convenience init(
urlSession: URLSession,
details: AutoDiscoveryAttemptSuccess,
username: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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()
Expand Down