Skip to content

Commit

Permalink
Merge pull request #20 from k-kohey/fix/parallelization
Browse files Browse the repository at this point in the history
decouple function calls from Actor
  • Loading branch information
k-kohey authored Jan 22, 2023
2 parents 36ad196 + c9fe7ba commit cbb7a83
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions Sources/Parchment/LoggerBundler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,18 @@ public final actor LoggerBundler {
/// - Parameters:
/// - event: Log to be sent
/// - option: Option the method and target of sending.
public func send(_ event: some Loggable, with option: LoggingOption = .init()) async {
assert(!components.isEmpty, "Should set the any logger")
let loggers: [any LoggerComponent] = {
public nonisolated func send(_ event: some Loggable, with option: LoggingOption = .init()) async {
func loggers() async -> [any LoggerComponent] {
if let scope = option.scope {
return components[scope]
return await components[scope]
} else {
return components
return await components
}
}()
}

await withTaskGroup(of: Void.self) { group in
for logger in loggers {
let record = BufferRecord(
for logger in await loggers() {
let record = await BufferRecord(
destination: logger.id.value,
event: mutations.transform(event, id: logger.id),
timestamp: .init()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Parchment/Mutation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public protocol Mutation {
public protocol Mutation: Sendable {
func transform(_: any Loggable, id: LoggerComponentID) -> any Loggable
}

Expand Down

0 comments on commit cbb7a83

Please sign in to comment.