Skip to content

Commit 4131d98

Browse files
authored
feat: fix Sendable warnings across the codebase (#46)
1 parent cbdec5f commit 4131d98

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

Sources/Casbin/APi/InternalApi.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ extension CoreApi {
7474
}
7575

7676

77-
private func afterOperatePolicy<T>(sec:String,oped:Bool,d:EventData,t:T) -> EventLoopFuture<T> {
77+
private func afterOperatePolicy<T: Sendable>(sec:String,oped:Bool,d:EventData,t:T) -> EventLoopFuture<T> {
7878
if oped {
7979
emit(e: Event.PolicyChange, d: d)
8080
emit(e: Event.ClearCache, d: EventData.ClearCache)
@@ -88,4 +88,3 @@ extension CoreApi {
8888
return eventLoopGroup.next().makeSucceededFuture(t)
8989
}
9090
}
91-

Sources/Casbin/Adapter/FileAdapter.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,18 @@ public final class FileAdapter {
7777

7878
extension FileAdapter: Adapter {
7979
public func loadPolicy(m: Model) -> EventLoopFuture<Void> {
80-
loadPolicyFile(m: m, handler:Util.loadPolicyLine(line:m:))
80+
// Wrap the handler in an explicit @Sendable closure to avoid warnings
81+
// about converting a non-sendable function to a @Sendable type.
82+
loadPolicyFile(m: m, handler: { (line: String, model: Model) in
83+
Util.loadPolicyLine(line: line, m: model)
84+
})
8185
}
8286

8387
public func loadFilteredPolicy(m: Model, f: Filter) -> EventLoopFuture<Void> {
84-
loadFilteredPolicyFile(m: m, filter: f, handler: Util.loadFilteredPolicyLine).map {
85-
self.isFiltered = $0
88+
loadFilteredPolicyFile(m: m, filter: f, handler: { (line: String, model: Model, filter: Filter) in
89+
Util.loadFilteredPolicyLine(line: line, m: model, f: filter)
90+
}).map { isFiltered in
91+
self.isFiltered = isFiltered
8692
}
8793
}
8894

Sources/Casbin/Config.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import NIO
1616

17-
public struct Config {
17+
public struct Config: Sendable {
1818
var data: [String:[String:String]] = [:]
1919
static let DEFAULT_SECTION = "default"
2020
static let DEFAULT_COMMENT:Character = "#"

0 commit comments

Comments
 (0)