diff --git a/Sources/RuleKit/Center.swift b/Sources/RuleKit/Center.swift index a00535f..c0da715 100644 --- a/Sources/RuleKit/Center.swift +++ b/Sources/RuleKit/Center.swift @@ -73,16 +73,16 @@ public final class RuleKit { } func donations(for event: Event) async -> Event.Donations { - (try? await store.donations(for: event)) ?? .empty + (try? store.donations(for: event)) ?? .empty } func lastTrigger(for trigger: any Trigger) async -> Date? { - try? await store.lastTrigger(of: trigger) + try? store.lastTrigger(of: trigger) } func donate(_ event: Event) async { do { - let previous = try await store.donations(for: event) + let previous = try store.donations(for: event) // Must implement first since it might be used twice (and result having different dates) let donation = Event.Donation.now let donations = Event.Donations( @@ -90,7 +90,7 @@ public final class RuleKit { first: previous.first ?? donation, last: donation ) - try await store.persist(donations, for: event) + try store.persist(donations, for: event) try await triggerFulfilledRules() } catch { logger.error("Donation failed for event \(event.rawValue) with error: \(error)") @@ -99,7 +99,7 @@ public final class RuleKit { func reset(_ event: Event) async { do { - try await store.persist(.empty, for: event) + try store.persist(.empty, for: event) } catch { logger.error("Reseting donations failed for event \(event.rawValue) with error: \(error)") } diff --git a/Sources/RuleKit/Store.swift b/Sources/RuleKit/Store.swift index d370db9..c8044a3 100644 --- a/Sources/RuleKit/Store.swift +++ b/Sources/RuleKit/Store.swift @@ -28,7 +28,8 @@ import Foundation extension RuleKit { - public actor Store { + @MainActor + public class Store { enum Error: Swift.Error { case missingGroupIdentifier case storeAlreadyConfigured @@ -68,6 +69,7 @@ extension RuleKit { } } + @MainActor func createStore() throws -> Store { var url = try self.url url.appendPathComponent("RuleKitEvents.plist")