PromiseKit/Sources/Configuration.swift
Garth Snyder a90ce6b5e8
Final cleanup for Dispatcher conversion (#1016)
* Additional comments for Dispatcher.swift
* Remove .promise namespacer from Dispatcher.dispatch -> Guarantee/Promise
* Convert to LogEvent system, groom logging and tests
* Expand DispatchQueueDispatcher to hold both a DispatchGroup and a QoS
* Finalize dispatcher.dispatch and related tests
* Clean up DispatchQueue wrapping, avoid assuming any particular defaults
* CurrentThreadDispatcher.dispatch needn't mark closure arg as @escaping
* Test that DispatchQueue.pmkDefault is identifiable with ===
* Documentation updates
* Build any v7* branch
* Rebuild Linux test manifest, check return types of Dispatcher.dispatch {}
2019-04-07 16:15:21 -04:00

37 lines
1.6 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Dispatch
/**
PromiseKits configurable parameters.
Do not change these after any Promise machinery executes as the configuration object is not thread-safe.
We would like it to be, but sadly `Swift` does not expose `dispatch_once` et al. which is what we used to use in order to make the configuration immutable once first used.
*/
public struct PMKConfiguration {
/// Backward compatibility: the default Dispatcher to which handlers dispatch, represented as DispatchQueues.
public var Q: (map: DispatchQueue?, return: DispatchQueue?) {
get {
let convertedMap = D.map is CurrentThreadDispatcher ? nil : D.map as? DispatchQueue
let convertedReturn = D.return is CurrentThreadDispatcher ? nil : D.return as? DispatchQueue
return (map: convertedMap, return: convertedReturn)
}
set { D = (map: newValue.map ?? CurrentThreadDispatcher(), return: newValue.return ?? CurrentThreadDispatcher()) }
}
/// The default Dispatchers to which promise handlers dispatch
public var D: (map: Dispatcher, return: Dispatcher) = (map: DispatchQueue.main, return: DispatchQueue.main)
/// The default catch-policy for all `catch` and `resolve`
public var catchPolicy = CatchPolicy.allErrorsExceptCancellation
/// The closure used to log PromiseKit events.
/// Not thread safe; change before processing any promises.
/// - Note: The default handler calls `print()`
public var logHandler: (LogEvent) -> () = { event in
print(event.asString())
}
}
/// Modify this as soon as possible in your applications lifetime
public var conf = PMKConfiguration()