Files
swift-composable-architectu…/Sources/ComposableArchitecture/Internal/DispatchQueue.swift
Stephen Celis a7e2e73f83 Swift 6: Key path sendability (#3282)
* `@preconcurrency @MainActor` isolation of `Store`

* Remove unneeded `@MainActor`s

* Remove thread checking code

* Remove unneeded `@MainActor`s

* Swift 5.10 compatibility fixes

* wip

* More 5.10 fixes

* wip

* fixes

* wip

* wip

* up the timeout

* wip

* Fixes

* wip

* wip

* wip

* wip

* wip

* Fix binding action sendability

* Address more binding action sendability

* more bindable action sendability

* more bindable action warnings

* fix

---------

Co-authored-by: Brandon Williams <mbrandonw@hey.com>
2024-08-29 13:46:39 -07:00

23 lines
522 B
Swift

import Dispatch
func mainActorNow<R: Sendable>(execute block: @MainActor @Sendable () -> R) -> R {
if DispatchQueue.getSpecific(key: key) == value {
return MainActor._assumeIsolated {
block()
}
} else {
return DispatchQueue.main.sync {
MainActor._assumeIsolated {
block()
}
}
}
}
private let key: DispatchSpecificKey<UInt8> = {
let key = DispatchSpecificKey<UInt8>()
DispatchQueue.main.setSpecific(key: key, value: value)
return key
}()
private let value: UInt8 = 0