From 1559798116954389859f8f02974c7fdeba3140d2 Mon Sep 17 00:00:00 2001 From: Igor Date: Mon, 25 Sep 2017 20:43:05 +0300 Subject: [PATCH] Fix synchronization --- CHANGELOG.md | 6 +++++- LeadKit.podspec | 2 +- Sources/Classes/Services/NetworkService.swift | 7 +++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00947a3b..3a49c701 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,4 +6,8 @@ ## 0.5.7 -- **Add**: String extension `localizedComponent(value:stringOne:stringTwo:stringMany:)` \ No newline at end of file +- **Add**: String extension `localizedComponent(value:stringOne:stringTwo:stringMany:)` + +## 0.5.8 + +- **Fix**: Synchronization over `NSRecursiveLock` for request count tracker in NetworkService diff --git a/LeadKit.podspec b/LeadKit.podspec index d03c2f32..c33bad11 100644 --- a/LeadKit.podspec +++ b/LeadKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "LeadKit" - s.version = "0.5.7" + s.version = "0.5.8" s.summary = "iOS framework with a bunch of tools for rapid development" s.homepage = "https://github.com/TouchInstinct/LeadKit" s.license = "Apache License, Version 2.0" diff --git a/Sources/Classes/Services/NetworkService.swift b/Sources/Classes/Services/NetworkService.swift index b62970c1..ad89b7b8 100644 --- a/Sources/Classes/Services/NetworkService.swift +++ b/Sources/Classes/Services/NetworkService.swift @@ -30,6 +30,9 @@ import RxAlamofire /// Has an ability to automatically show / hide network activity indicator open class NetworkService { + /// Enable synchronization for setting variable from different thread + private let lock = NSRecursiveLock() + private let requestCountVariable = Variable(0) public let sessionManager: Alamofire.SessionManager @@ -68,11 +71,15 @@ open class NetworkService { } fileprivate func increaseRequestCounter() { + lock.lock() requestCountVariable.value += 1 + lock.unlock() } fileprivate func decreaseRequestCounter() { + lock.lock() requestCountVariable.value -= 1 + lock.unlock() } }