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.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
vmartinelli committed Sep 3, 2015
2 parents c06a26e + 49a4141 commit d64d341
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 31 deletions.
2 changes: 1 addition & 1 deletion 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.1.1"
s.version = "1.1.2"
s.summary = "Bringing async and await to Swift world with some flavouring."
s.homepage = "https://github.com/Alecrim/AlecrimAsyncKit"

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ If any of the task conditions is not satisfied the task will not be started. Onl

A task can have its beginning and its ending observed using the `TaskObserver` class instances. The observers can be passed to the `async` global function when a task is created.

The **AlecrimAsyncKit** framework provides some predefined observers, but you can created others.
The **AlecrimAsyncKit** framework provides some predefined observers, but you can create others.

```swift
func asyncDoSomething() -> Task<Void> {
Expand Down Expand Up @@ -225,7 +225,7 @@ The difference between a failable task and a non-failable task when running them

### Considerations

After its creation the task is immediately started in background. It's completion can be "awaited" using the `await` global function, that blocks the current thread until the task finishes. When finished the task return value is available and the next line after the `await` call is performed normally.
After its creation the task is immediately started in background. Its completion can be "awaited" using the `await` global function, that blocks the current thread until the task finishes. When finished the task return value is available and the next line after the `await` call is performed normally.

If a task is not "awaited" it will be performed anyway. In this case no code in any thread will be blocked and its returning value will be discarded.

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 @@ -317,7 +317,7 @@
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 81;
CURRENT_PROJECT_VERSION = 83;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -339,7 +339,7 @@
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 81;
CURRENT_PROJECT_VERSION = 83;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand Down
58 changes: 33 additions & 25 deletions Source/AlecrimAsyncKit/Core/Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,41 +126,49 @@ public final class Task<V>: BaseTask<V>, FailableTaskType {
internal init(queue: NSOperationQueue, observers: [TaskObserver]?, conditions: [TaskCondition]?, closure: (Task<V>) -> Void) {
assert(queue.maxConcurrentOperationCount == NSOperationQueueDefaultMaxConcurrentOperationCount || queue.maxConcurrentOperationCount > 1, "Task `queue` cannot be the main queue nor a serial queue.")
super.init()

do {
if let conditions = conditions where !conditions.isEmpty {
let mutuallyExclusiveConditions = conditions.flatMap { $0 as? MutuallyExclusiveTaskCondition }
if !mutuallyExclusiveConditions.isEmpty {
mutuallyExclusiveConditions.forEach { mutuallyExclusiveCondition in
MutuallyExclusiveTaskCondition.increment(mutuallyExclusiveCondition.categoryName)

queue.addOperationWithBlock {
do {
//
if let conditions = conditions where !conditions.isEmpty {
//
guard !self.cancelled else { return }

//
let mutuallyExclusiveConditions = conditions.flatMap { $0 as? MutuallyExclusiveTaskCondition }
if !mutuallyExclusiveConditions.isEmpty {
mutuallyExclusiveConditions.forEach { mutuallyExclusiveCondition in
MutuallyExclusiveTaskCondition.increment(mutuallyExclusiveCondition.categoryName)
}

self.addDeferredClosure {
MutuallyExclusiveTaskCondition.decrement(mutuallyExclusiveCondition.categoryName)
mutuallyExclusiveConditions.forEach { mutuallyExclusiveCondition in
MutuallyExclusiveTaskCondition.decrement(mutuallyExclusiveCondition.categoryName)
}
}
}

//
try await(TaskCondition.asyncEvaluateConditions(conditions))
}

//
try await(TaskCondition.asyncEvaluateConditions(conditions))
}

if !self.cancelled {
queue.addOperationWithBlock {
if !self.cancelled {
if let observers = observers where !observers.isEmpty {
observers.forEach { $0.taskDidStart(self) }
self.addDeferredClosure { [unowned self] in
observers.forEach { $0.taskDidFinish(self) }
}
}

closure(self)
guard !self.cancelled else { return }

//
if let observers = observers where !observers.isEmpty {
observers.forEach { $0.taskDidStart(self) }
self.addDeferredClosure { [unowned self] in
observers.forEach { $0.taskDidFinish(self) }
}
}

//
closure(self)
}
catch let error {
self.finishWithError(error)
}
}
catch let error {
self.finishWithError(error)
}
}

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.1.1</string>
<string>1.1.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down

0 comments on commit d64d341

Please sign in to comment.