From e853de4e657f63c28ae82f2bcafa557d64ff4d83 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Tue, 19 Mar 2024 15:36:58 +0700 Subject: [PATCH] Add Sendable to SupabaseLogMessage --- Examples/SlackClone/Logger.swift | 11 ++++++++++- Examples/SlackClone/Supabase.swift | 2 +- Sources/_Helpers/SupabaseLogger.swift | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Examples/SlackClone/Logger.swift b/Examples/SlackClone/Logger.swift index 8905700a..396b5adf 100644 --- a/Examples/SlackClone/Logger.swift +++ b/Examples/SlackClone/Logger.swift @@ -20,10 +20,14 @@ final class LogStore: SupabaseLogger { static let shared = LogStore() + @MainActor var messages: [SupabaseLogMessage] = [] func log(message: SupabaseLogMessage) { - messages.append(message) + Task { + await add(message: message) + } + lock.withLock { if loggers[message.system] == nil { loggers[message.system] = Logger( @@ -42,4 +46,9 @@ final class LogStore: SupabaseLogger { } } } + + @MainActor + private func add(message: SupabaseLogMessage) { + messages.insert(message, at: 0) + } } diff --git a/Examples/SlackClone/Supabase.swift b/Examples/SlackClone/Supabase.swift index dcd3c3e9..9581d3dc 100644 --- a/Examples/SlackClone/Supabase.swift +++ b/Examples/SlackClone/Supabase.swift @@ -21,7 +21,7 @@ let decoder: JSONDecoder = { }() let supabase = SupabaseClient( - supabaseURL: URL(string: "http://192.168.0.6:54321")!, + supabaseURL: URL(string: "http://localhost:54321")!, supabaseKey: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0", options: SupabaseClientOptions( db: .init(encoder: encoder, decoder: decoder), diff --git a/Sources/_Helpers/SupabaseLogger.swift b/Sources/_Helpers/SupabaseLogger.swift index fe8ed7a0..de458f98 100644 --- a/Sources/_Helpers/SupabaseLogger.swift +++ b/Sources/_Helpers/SupabaseLogger.swift @@ -16,7 +16,7 @@ public enum SupabaseLogLevel: Int, Codable, CustomStringConvertible, Sendable { } } -public struct SupabaseLogMessage: Codable, CustomStringConvertible { +public struct SupabaseLogMessage: Codable, CustomStringConvertible, Sendable { public let system: String public let level: SupabaseLogLevel public let message: String