Slather logo

Coverage for "MainThreadChecking.swift" : 57.14%

(4 of 7 relevant lines covered)

RouteComposer/Classes/Router/Internal/MainThreadChecking.swift

1
//
2
// RouteComposer
3
// MainThreadChecking.swift
4
// https://github.com/ekazaev/route-composer
5
//
6
// Created by Eugene Kazaev in 2018-2022.
7
// Distributed under the MIT license.
8
//
9
// Become a sponsor:
10
// https://github.com/sponsors/ekazaev
11
//
12
13
import Foundation
14
15
protocol MainThreadChecking {}
16
17
extension MainThreadChecking {
18
19
    func assertIfNotMainThread(functionName: String = #function, logger: Logger? = nil) {
2110x
20
        if !Thread.isMainThread {
2110x
21
            let errorMessage = "Internal inconsistency: Method \(functionName) requires to be called on the main thread."
!
22
            logger?.log(.error(errorMessage))
!
23
            assertionFailure(errorMessage)
!
24
        }
2110x
25
    }
2110x
26
27
}