Skip to content
This repository has been archived by the owner on Feb 28, 2020. It is now read-only.

Commit

Permalink
Merge branch 'release/1.2.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
vmartinelli committed Sep 22, 2015
2 parents aa6e46f + 73706ff commit b97d5be
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 48 deletions.
7 changes: 4 additions & 3 deletions AlecrimAsyncKit.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "AlecrimAsyncKit"
s.version = "1.2.2"
s.version = "1.2.3"
s.summary = "Bringing async and await to Swift world with some flavouring."
s.homepage = "https://github.com/Alecrim/AlecrimAsyncKit"

Expand All @@ -10,8 +10,9 @@ Pod::Spec.new do |s|
s.author = { "Vanderlei Martinelli" => "[email protected]" }
s.social_media_url = "https://twitter.com/vmartinelli"

s.ios.deployment_target = "8.0"
s.osx.deployment_target = "10.10"
s.ios.deployment_target = "8.0"
s.osx.deployment_target = "10.10"
s.watchos.deployment_target = "2.0"

s.source = { :git => "https://github.com/Alecrim/AlecrimAsyncKit.git", :tag => s.version }

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func asyncDoSomething() -> Task<Void> {

#### Conditions

One or many conditions (that can be either "satisfied" or "failed") can be taken into account before a task is started.
One or many conditions (that can be either "satisfied", "not satisfied" or "failed") can be taken into account before a task is started.

A condition is an instance from the `TaskCondition` class that can be passed as parameter to the `async` global function when a task is created.

Expand All @@ -157,7 +157,7 @@ func asyncDoSomething() -> Task<Void> {
result(.Satisfied)
}
else {
result(.FailedWithError(NSError(...)))
result(.Failed(NSError(...)))
}
}

Expand Down
4 changes: 2 additions & 2 deletions Source/AlecrimAsyncKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 105;
CURRENT_PROJECT_VERSION = 107;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -385,7 +385,7 @@
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 105;
CURRENT_PROJECT_VERSION = 107;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "14E585BA1B7803EC003EC4DC"
BuildableName = "AlecrimAsyncKit.framework"
BlueprintName = "AlecrimAsyncKit"
ReferencedContainer = "container:AlecrimAsyncKit.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "14E585BA1B7803EC003EC4DC"
BuildableName = "AlecrimAsyncKit.framework"
BlueprintName = "AlecrimAsyncKit"
ReferencedContainer = "container:AlecrimAsyncKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "14E585BA1B7803EC003EC4DC"
BuildableName = "AlecrimAsyncKit.framework"
BlueprintName = "AlecrimAsyncKit"
ReferencedContainer = "container:AlecrimAsyncKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ public final class TimeoutTaskObserver: TaskObserver {
weak var weakTask = task

let when = dispatch_time(DISPATCH_TIME_NOW, Int64(timeout * Double(NSEC_PER_SEC)))
dispatch_after(when, dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0)) {

let queue: dispatch_queue_t
if #available(OSXApplicationExtension 10.10, *) {
queue = dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0)
} else {
queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
}

dispatch_after(when, queue) {
if let strongTask = weakTask as? FailableTaskType {
strongTask.cancel()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,50 @@ import Foundation

#if os(iOS)

private var _activitySpinLock = OS_SPINLOCK_INIT
private var _activity: Int = 0

/// A task observer that will cause the network activity indicator to appear as long as the observed task is executing.
public final class NetworkActivityTaskObserver: TaskObserver {


private static var _activitySpinLock = OS_SPINLOCK_INIT
private static var _activity: Int = 0

private let delay: NSTimeInterval = 0.5
private let application: UIApplication

private var activity: Int {
get {
withUnsafeMutablePointer(&_activitySpinLock, OSSpinLockLock)
let v = _activity
withUnsafeMutablePointer(&_activitySpinLock, OSSpinLockUnlock)
private func incrementActivity() {
withUnsafeMutablePointer(&NetworkActivityTaskObserver._activitySpinLock, OSSpinLockLock)
NetworkActivityTaskObserver._activity++
withUnsafeMutablePointer(&NetworkActivityTaskObserver._activitySpinLock, OSSpinLockUnlock)

self.showOrHideActivityIndicatorAfterDelay()
}

private func decrementActivity() {
withUnsafeMutablePointer(&NetworkActivityTaskObserver._activitySpinLock, OSSpinLockLock)
NetworkActivityTaskObserver._activity--
withUnsafeMutablePointer(&NetworkActivityTaskObserver._activitySpinLock, OSSpinLockUnlock)

self.showOrHideActivityIndicatorAfterDelay()
}

private func showOrHideActivityIndicatorAfterDelay() {
let when = dispatch_time(DISPATCH_TIME_NOW, Int64(self.delay * Double(NSEC_PER_SEC)))
dispatch_after(when, dispatch_get_main_queue()) {
withUnsafeMutablePointer(&NetworkActivityTaskObserver._activitySpinLock, OSSpinLockLock)

return v
}
set {
withUnsafeMutablePointer(&_activitySpinLock, OSSpinLockLock)
_activity = newValue
withUnsafeMutablePointer(&_activitySpinLock, OSSpinLockUnlock)
let value = NetworkActivityTaskObserver._activity

if self.activity > 0 {
let when = dispatch_time(DISPATCH_TIME_NOW, Int64(self.delay * Double(NSEC_PER_SEC)))
dispatch_after(when, dispatch_get_main_queue()) {
if self.activity > 0 {
self.application.networkActivityIndicatorVisible = true
}
}
if value > 0 {
self.application.networkActivityIndicatorVisible = true
}
else {
let when = dispatch_time(DISPATCH_TIME_NOW, Int64((self.delay / 2.0) * Double(NSEC_PER_SEC)))
dispatch_after(when, dispatch_get_main_queue()) {
if self.activity == 0 {
self.application.networkActivityIndicatorVisible = false
}
}
self.application.networkActivityIndicatorVisible = false
}

withUnsafeMutablePointer(&NetworkActivityTaskObserver._activitySpinLock, OSSpinLockUnlock)

}
}

/// Initializes a task observer that will cause the network activity indicator to appear as long as the observed task is executing.
///
/// - parameter application: The application where the network activity indicator belongs to.
Expand All @@ -63,11 +66,11 @@ public final class NetworkActivityTaskObserver: TaskObserver {
super.init()

self.didStart { [unowned self] _ in
self.activity++
self.incrementActivity()
}

self.didFinish { [unowned self] _ in
self.activity--
self.decrementActivity()
}
}

Expand Down
22 changes: 15 additions & 7 deletions Source/AlecrimAsyncKit/Core/AsyncAwait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import Foundation
private let _defaultTaskQueue: NSOperationQueue = {
let queue = NSOperationQueue()
queue.name = "com.alecrim.AlecrimAsyncKit.Task"
queue.qualityOfService = .Background

if #available(OSXApplicationExtension 10.10, *) {
queue.qualityOfService = .Background
}

queue.maxConcurrentOperationCount = NSOperationQueueDefaultMaxConcurrentOperationCount

return queue
Expand All @@ -20,7 +24,11 @@ private let _defaultTaskQueue: NSOperationQueue = {
private let _defaultRunTaskQueue: NSOperationQueue = {
let queue = NSOperationQueue()
queue.name = "com.alecrim.AlecrimAsyncKit.RunTask"
queue.qualityOfService = .Background

if #available(OSXApplicationExtension 10.10, *) {
queue.qualityOfService = .Background
}

queue.maxConcurrentOperationCount = NSOperationQueueDefaultMaxConcurrentOperationCount

return queue
Expand Down Expand Up @@ -294,7 +302,7 @@ public func asyncEx<V>(queue: NSOperationQueue = _defaultTaskQueue, observers: [

/// Waits for the completion of a task and then returns its value.
///
/// - parameter closure: The closure that returns a initialized task.
/// - parameter closure: The closure that returns an initialized task.
///
/// - throws: Any error occurred while task was executing.
///
Expand All @@ -305,7 +313,7 @@ public func await<V>(@noescape closure: () -> Task<V>) throws -> V {

/// Waits for the completion of a task and then returns its value.
///
/// - parameter task: A initialized task.
/// - parameter task: An initialized task.
///
/// - throws: Any error occurred while task was executing.
///
Expand Down Expand Up @@ -346,7 +354,7 @@ public func runTask<V>(task: Task<V>, queue: NSOperationQueue = _defaultRunTaskQ

/// Waits for the completion of a non-failable task and then returns its value.
///
/// - parameter closure: The closure that returns a initialized non-failable task.
/// - parameter closure: The closure that returns an initialized non-failable task.
///
/// - returns: The non-failable task's associated value.
public func await<V>(@noescape closure: () -> NonFailableTask<V>) -> V {
Expand All @@ -355,14 +363,14 @@ public func await<V>(@noescape closure: () -> NonFailableTask<V>) -> V {

/// Waits for the completion of a non-failable task and then returns its value.
///
/// - parameter task: A initialized non-failable task.
/// - parameter task: An initialized non-failable task.
///
/// - returns: The non-failable task's associated value.
public func await<V>(task: NonFailableTask<V>) -> V {
return task.waitForCompletionAndReturnValue()
}

/// Runs a non-failable task in a background queue and the call the completion handler with its associated value.
/// Runs a non-failable task in a background queue and then calls the completion handler with its associated value.
///
/// - parameter task: The non-failable task to run.
/// - parameter queue: The queue where the task will be "awaited".
Expand Down
6 changes: 5 additions & 1 deletion Source/AlecrimAsyncKit/Core/TaskCondition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import Foundation
private let _defaultTaskConditionQueue: NSOperationQueue = {
let queue = NSOperationQueue()
queue.name = "com.alecrim.AlecrimAsyncKit.TaskCondition"
queue.qualityOfService = .Background

if #available(OSXApplicationExtension 10.10, *) {
queue.qualityOfService = .Background
}

queue.maxConcurrentOperationCount = NSOperationQueueDefaultMaxConcurrentOperationCount

return queue
Expand Down
2 changes: 1 addition & 1 deletion Source/AlecrimAsyncKit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.2.2</string>
<string>1.2.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down

0 comments on commit b97d5be

Please sign in to comment.