Permalink
Browse files

migrate configuration loader to syncronous

  • Loading branch information...
leogdion committed Oct 20, 2016
1 parent 3f57444 commit d25001ea0d50fad725a068ecd3e4744d85a18e4f
@@ -35,7 +35,7 @@ public struct Speculid {
exceptionHandler = tracker.track
let configLoader = SpeculidConfigurationLoader(dataSources: [SearchApplicationPathDataSource(), ConfiguredApplicationPathDataSource(), DefaultApplicationPathDataSource()])
let configLoader = SpeculidConfigurationLoader(dataSources: [ConfiguredApplicationPathDataSource(), DefaultApplicationPathDataSource(), SearchApplicationPathDataSource()])
tracker.track(event: AnalyticsEvent(category: "main", action: "launch", label: "application"))
@@ -18,37 +18,35 @@ public struct SpeculidConfigurationLoader : SpeculidConfigurationLoaderProtocol
public func load(_ closure: @escaping (SpeculidConfigurationProtocol) -> Void) {
DispatchQueue.main.async {
var applicationPathSets = Array(repeating: ApplicationPathDictionary(), count: self.dataSources.count)
let group = DispatchGroup()
/*
DispatchQueue.main.async(group: group, qos: DispatchQoS.default, flags: DispatchWorkItemFlags(), execute: {
})
*/
var valuesSet = false
let queue = DispatchQueue(label: Speculid.bundle.bundleIdentifier!+".configuration.queue")
var applicationPaths = ApplicationPathDictionary()
for (index,dataSource) in self.dataSources.enumerated() {
group.enter()
dataSource.applicationPaths({ (newPaths) in
applicationPathSets[index] = newPaths
group.leave()
for dataSource in self.dataSources {
queue.sync(execute: {
if valuesSet {
return
}
dataSource.applicationPaths({ (paths) in
for (type, url) in paths {
if applicationPaths[type] == nil {
applicationPaths[type] = url
}
}
var allSet = true
for type in ApplicationPath.values {
if applicationPaths[type] == nil {
allSet = false
break
}
}
valuesSet = allSet
})
})
}
var applicationPaths = ApplicationPathDictionary()
group.notify(queue: .main, execute: {
for paths in applicationPathSets {
for (type, url) in paths {
if applicationPaths[type] == nil {
applicationPaths[type] = url
}
}
}
closure(SpeculidConfiguration(applicationPaths: applicationPaths))
})
closure(SpeculidConfiguration(applicationPaths: applicationPaths))
}
}
}
@@ -9,4 +9,6 @@
public enum ApplicationPath : String {
case inkscape = "inkscape",
convert = "convert"
public static let values : [ApplicationPath] = [.inkscape, .convert]
}
View
@@ -3,16 +3,16 @@
let VCS_TYPE = "git"
let VCS_BASENAME = "speculid"
let VCS_UUID: String? = "b6fd659a7d2088d5420f962a307b1f7f7e5d0604"
let VCS_NUM: Int = 424
let VCS_DATE = "2016-10-19T17:12:51Z"
let VCS_NUM: Int = 425
let VCS_DATE = "2016-10-19T21:21:28Z"
let VCS_BRANCH: String = "feature/issue-08-auto-paths"
let VCS_TAG: String? = "1.0.0-beta2"
let VCS_TICK: Int? = 1
let VCS_EXTRA: String? = "21"
let VCS_TICK: Int? = 2
let VCS_EXTRA: String? = "2"
let VCS_ACTION_STAMP: String? = "2016-10-19T17:12:51Z!leogdion@brightdigit.com"
let VCS_FULL_HASH: String = "6b958f0372b54e191a21be108ccc129fadad02a8"
let VCS_SHORT_HASH: String = "6b958f0"
let VCS_ACTION_STAMP: String? = "2016-10-19T21:21:28Z!leogdion@brightdigit.com"
let VCS_FULL_HASH: String = "3f57444a2ec6cf9ab301089f62ee70d429914fb3"
let VCS_SHORT_HASH: String = "3f57444"
let VCS_WC_MODIFIED: Bool = true

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit d25001e

Please sign in to comment.