Merge pull request #25 from kukukk/master
iOS: clean up by removing the handled response
This commit is contained in:
commit
9a4369ce57
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
<platform name="ios">
|
<platform name="ios">
|
||||||
<source-file src="src/ios/Webserver.swift" />
|
<source-file src="src/ios/Webserver.swift" />
|
||||||
|
<source-file src="src/ios/SynchronizedDictionary.swift" />
|
||||||
<dependency id="cordova-plugin-add-swift-support" version="1.6.1"/>
|
<dependency id="cordova-plugin-add-swift-support" version="1.6.1"/>
|
||||||
|
|
||||||
<framework src="libz.tbd" />
|
<framework src="libz.tbd" />
|
||||||
|
25
src/ios/SynchronizedDictionary.swift
Normal file
25
src/ios/SynchronizedDictionary.swift
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
public class SynchronizedDictionary<KeyType:Hashable, ValueType> {
|
||||||
|
private var dictionary: [KeyType:ValueType] = [:]
|
||||||
|
private let accessQueue = DispatchQueue(label: "SynchronizedDictionaryAccess", attributes: .concurrent)
|
||||||
|
|
||||||
|
public func removeValue(forKey: KeyType) {
|
||||||
|
self.accessQueue.async(flags:.barrier) {
|
||||||
|
self.dictionary.removeValue(forKey: forKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public subscript(key: KeyType) -> ValueType? {
|
||||||
|
set {
|
||||||
|
self.accessQueue.async(flags:.barrier) {
|
||||||
|
self.dictionary[key] = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
get {
|
||||||
|
var element: ValueType?
|
||||||
|
self.accessQueue.sync {
|
||||||
|
element = self.dictionary[key]
|
||||||
|
}
|
||||||
|
return element
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,13 +3,13 @@
|
|||||||
let TIMEOUT: Int = 60 * 3 * 1000000
|
let TIMEOUT: Int = 60 * 3 * 1000000
|
||||||
|
|
||||||
var webServer: GCDWebServer = GCDWebServer()
|
var webServer: GCDWebServer = GCDWebServer()
|
||||||
var responses: Dictionary<String, Any> = [:]
|
var responses = SynchronizedDictionary<AnyHashable,Any?>()
|
||||||
var onRequestCommand: CDVInvokedUrlCommand? = nil
|
var onRequestCommand: CDVInvokedUrlCommand? = nil
|
||||||
|
|
||||||
override func pluginInitialize() {
|
override func pluginInitialize() {
|
||||||
self.webServer = GCDWebServer()
|
self.webServer = GCDWebServer()
|
||||||
self.onRequestCommand = nil
|
self.onRequestCommand = nil
|
||||||
self.responses = [:]
|
self.responses = SynchronizedDictionary<AnyHashable,Any?>()
|
||||||
self.initHTTPRequestHandlers()
|
self.initHTTPRequestHandlers()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,6 +63,9 @@
|
|||||||
response?.setValue(value, forAdditionalHeader: key)
|
response?.setValue(value, forAdditionalHeader: key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove the handled response
|
||||||
|
self.responses.removeValue(forKey: requestUUID)
|
||||||
|
|
||||||
// Complete the async response
|
// Complete the async response
|
||||||
completionBlock(response!)
|
completionBlock(response!)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user