Mark ArticleStatus.Key as Sendable. Put the locks in the right places.

This commit is contained in:
Brent Simmons 2024-04-04 20:44:40 -07:00
parent 7f71223387
commit 26de8d8b9c
1 changed files with 18 additions and 6 deletions

View File

@ -17,7 +17,7 @@ import os
/// by an internal lock, which makes `ArticleStatus` thread-safe.
public final class ArticleStatus: Hashable, @unchecked Sendable {
public enum Key: String {
public enum Key: String, Sendable {
case read = "read"
case starred = "starred"
}
@ -38,6 +38,14 @@ public final class ArticleStatus: Hashable, @unchecked Sendable {
return _read
}
set {
Self.lock.lock()
defer {
Self.lock.unlock()
}
_read = newValue
}
}
public var starred: Bool {
@ -49,6 +57,14 @@ public final class ArticleStatus: Hashable, @unchecked Sendable {
return _starred
}
set {
Self.lock.lock()
defer {
Self.lock.unlock()
}
_starred = newValue
}
}
private var _read = false
@ -66,6 +82,7 @@ public final class ArticleStatus: Hashable, @unchecked Sendable {
}
public func boolStatus(forKey key: ArticleStatus.Key) -> Bool {
switch key {
case .read:
return read
@ -76,11 +93,6 @@ public final class ArticleStatus: Hashable, @unchecked Sendable {
public func setBoolStatus(_ status: Bool, forKey key: ArticleStatus.Key) {
Self.lock.lock()
defer {
Self.lock.unlock()
}
switch key {
case .read:
_read = status