Skip to content

Commit

Permalink
Suppress sendability warnings on single-threaded platform
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed Nov 28, 2024
1 parent e2f569a commit 5b79ddf
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Sources/JavaScriptKit/ThreadLocal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,14 @@ final class ThreadLocal<Value>: Sendable {
}
#else
// Fallback implementation for platforms that don't support pthread
#if compiler(>=5.10)
nonisolated(unsafe) var wrappedValue: Value?
#else
var wrappedValue: Value?
#endif
private class SendableBox: @unchecked Sendable {
var value: Value? = nil
}
private let _storage = SendableBox()
var wrappedValue: Value? {
get { _storage.value }
set { _storage.value = newValue }
}

init() where Value: AnyObject {
wrappedValue = nil
Expand Down

0 comments on commit 5b79ddf

Please sign in to comment.