Files
CoreStore/Demo/Sources/Helpers/WithMainActorImmediate.swift
T
2026-07-28 14:25:01 +09:00

33 lines
520 B
Swift

//
// WithMainActorImmediate.swift
// Demo
//
// Created by John Estropia on 2026/07/21.
//
import Foundation
// MARK: - withMainActorImmediate
func withMainActorImmediate(
_ task: @MainActor @Sendable @escaping () -> Void
) {
if #available(iOS 26.0, *) {
Task.immediate(operation: task)
}
else if Thread.isMainThread {
MainActor.assumeIsolated {
task()
}
}
else {
Task.init(operation: task)
}
}