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/2.0-beta.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
vmartinelli committed Oct 26, 2015
2 parents 1d97c79 + 5485f04 commit c2ab771
Show file tree
Hide file tree
Showing 21 changed files with 1,050 additions and 909 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.3-beta.1"
s.version = "2.0-beta.1"
s.summary = "Bringing async and await to Swift world with some flavouring."
s.homepage = "https://github.com/Alecrim/AlecrimAsyncKit"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,25 @@ extension ViewController {
@IBAction func oneButtonPressed(sender: UIButton) {
sender.hidden = true
self.t1.finish() // yes, we can finish the task outside its inner block
self.t1 = nil // we do not it anymore
}

@IBAction func twoButtonPressed(sender: UIButton) {
sender.hidden = true
self.t2.finish()
self.t2 = nil // we do not it anymore
}

@IBAction func threeButtonPressed(sender: UIButton) {
sender.hidden = true
self.t3.finish()
self.t3 = nil // we do not it anymore
}

@IBAction func fourButtonPressed(sender: UIButton) {
sender.hidden = true
self.t4.finish()
self.t4 = nil // we do not it anymore
}

}
Expand All @@ -160,7 +164,7 @@ extension ViewController {

func asyncLoadImage() -> Task<UIImage> {
// an observer is not needed to the task finish its job, but to have a network activity indicator at the top would be nice...
let networkActivityObserver = UIApplication.sharedApplication().networkActivityTaskObserver
let networkActivityObserver = UIApplication.sharedApplication().networkActivityIndicatorTaskObserver()

// if you replace 10 for 2, for example, the task will be cancelled before it is finished
let timeoutObserver = TimeoutTaskObserver(timeout: 10)
Expand Down
60 changes: 38 additions & 22 deletions Source/AlecrimAsyncKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,56 @@
objects = {

/* Begin PBXBuildFile section */
143045511BB7AB5900CD0AED /* TaskType+Activity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 143045501BB7AB5900CD0AED /* TaskType+Activity.swift */; };
1413F62C1BDCAE56001049D5 /* TaskState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1413F62B1BDCAE56001049D5 /* TaskState.swift */; };
1413F62E1BDCAE8B001049D5 /* TaskType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1413F62D1BDCAE8B001049D5 /* TaskType.swift */; };
1416E08D1BDC931A00F1EA73 /* TaskObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1416E08C1BDC931A00F1EA73 /* TaskObserver.swift */; };
143045511BB7AB5900CD0AED /* ProcessInfoActivityTaskObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 143045501BB7AB5900CD0AED /* ProcessInfoActivityTaskObserver.swift */; };
14749B841B9C437700661E98 /* EventStorePermissionTaskCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14749B831B9C437700661E98 /* EventStorePermissionTaskCondition.swift */; };
14749B861B9C4DA300661E98 /* BooleanTaskCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14749B851B9C4DA300661E98 /* BooleanTaskCondition.swift */; };
147B5F371B9CFB0700F9F2CE /* TaskType+BackgroundTaskObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 147B5F361B9CFB0700F9F2CE /* TaskType+BackgroundTaskObserver.swift */; };
147B5F371B9CFB0700F9F2CE /* ApplicationBackgroundTaskObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 147B5F361B9CFB0700F9F2CE /* ApplicationBackgroundTaskObserver.swift */; };
1485139D1B9BD15100FAB0FA /* DelayTaskCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1485138C1B9BD15100FAB0FA /* DelayTaskCondition.swift */; };
1485139E1B9BD15100FAB0FA /* NegateTaskCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1485138D1B9BD15100FAB0FA /* NegateTaskCondition.swift */; };
1485139F1B9BD15100FAB0FA /* SilentTaskCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1485138E1B9BD15100FAB0FA /* SilentTaskCondition.swift */; };
148513A01B9BD15100FAB0FA /* PassLibraryAvailableCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 148513901B9BD15100FAB0FA /* PassLibraryAvailableCondition.swift */; };
148513A11B9BD15100FAB0FA /* PhotosPermissionTaskCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 148513911B9BD15100FAB0FA /* PhotosPermissionTaskCondition.swift */; };
148513A21B9BD15100FAB0FA /* ReachabilityTaskCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 148513921B9BD15100FAB0FA /* ReachabilityTaskCondition.swift */; };
148513A31B9BD15100FAB0FA /* RemoteNotificationPermissionTaskCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 148513931B9BD15100FAB0FA /* RemoteNotificationPermissionTaskCondition.swift */; };
148513A41B9BD15100FAB0FA /* AsyncAwait.swift in Sources */ = {isa = PBXBuildFile; fileRef = 148513951B9BD15100FAB0FA /* AsyncAwait.swift */; };
148513A41B9BD15100FAB0FA /* TaskBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 148513951B9BD15100FAB0FA /* TaskBuilder.swift */; };
148513A51B9BD15100FAB0FA /* Errors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 148513961B9BD15100FAB0FA /* Errors.swift */; };
148513A61B9BD15100FAB0FA /* MutuallyExclusiveTaskCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 148513971B9BD15100FAB0FA /* MutuallyExclusiveTaskCondition.swift */; };
148513A71B9BD15100FAB0FA /* Task.swift in Sources */ = {isa = PBXBuildFile; fileRef = 148513981B9BD15100FAB0FA /* Task.swift */; };
148513A81B9BD15100FAB0FA /* TaskCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 148513991B9BD15100FAB0FA /* TaskCondition.swift */; };
148513AC1B9BD19700FAB0FA /* TaskType+NetworkActivityIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 148513AB1B9BD19700FAB0FA /* TaskType+NetworkActivityIndicator.swift */; };
148513AC1B9BD19700FAB0FA /* NetworkActivityIndicatorTaskObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 148513AB1B9BD19700FAB0FA /* NetworkActivityIndicatorTaskObserver.swift */; };
148513AE1B9BD38100FAB0FA /* LocationPermissionTaskCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 148513AD1B9BD38100FAB0FA /* LocationPermissionTaskCondition.swift */; };
148513B11B9BD9A500FAB0FA /* FailableTaskType+Timeout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 148513B01B9BD9A500FAB0FA /* FailableTaskType+Timeout.swift */; };
148513B11B9BD9A500FAB0FA /* TimeoutTaskObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 148513B01B9BD9A500FAB0FA /* TimeoutTaskObserver.swift */; };
14C290401BDE544B006F1BB3 /* TaskWaiter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14C2903F1BDE544B006F1BB3 /* TaskWaiter.swift */; };
14E585BF1B7803EC003EC4DC /* AlecrimAsyncKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 14E585BE1B7803EC003EC4DC /* AlecrimAsyncKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
143045501BB7AB5900CD0AED /* TaskType+Activity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TaskType+Activity.swift"; sourceTree = "<group>"; };
1413F62B1BDCAE56001049D5 /* TaskState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TaskState.swift; sourceTree = "<group>"; };
1413F62D1BDCAE8B001049D5 /* TaskType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TaskType.swift; sourceTree = "<group>"; };
1416E08C1BDC931A00F1EA73 /* TaskObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TaskObserver.swift; sourceTree = "<group>"; };
143045501BB7AB5900CD0AED /* ProcessInfoActivityTaskObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProcessInfoActivityTaskObserver.swift; sourceTree = "<group>"; };
14749B831B9C437700661E98 /* EventStorePermissionTaskCondition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventStorePermissionTaskCondition.swift; sourceTree = "<group>"; };
14749B851B9C4DA300661E98 /* BooleanTaskCondition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BooleanTaskCondition.swift; sourceTree = "<group>"; };
147B5F361B9CFB0700F9F2CE /* TaskType+BackgroundTaskObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TaskType+BackgroundTaskObserver.swift"; sourceTree = "<group>"; };
147B5F361B9CFB0700F9F2CE /* ApplicationBackgroundTaskObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApplicationBackgroundTaskObserver.swift; sourceTree = "<group>"; };
1485138C1B9BD15100FAB0FA /* DelayTaskCondition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DelayTaskCondition.swift; sourceTree = "<group>"; };
1485138D1B9BD15100FAB0FA /* NegateTaskCondition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NegateTaskCondition.swift; sourceTree = "<group>"; };
1485138E1B9BD15100FAB0FA /* SilentTaskCondition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SilentTaskCondition.swift; sourceTree = "<group>"; };
148513901B9BD15100FAB0FA /* PassLibraryAvailableCondition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PassLibraryAvailableCondition.swift; sourceTree = "<group>"; };
148513911B9BD15100FAB0FA /* PhotosPermissionTaskCondition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotosPermissionTaskCondition.swift; sourceTree = "<group>"; };
148513921B9BD15100FAB0FA /* ReachabilityTaskCondition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReachabilityTaskCondition.swift; sourceTree = "<group>"; };
148513931B9BD15100FAB0FA /* RemoteNotificationPermissionTaskCondition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RemoteNotificationPermissionTaskCondition.swift; sourceTree = "<group>"; };
148513951B9BD15100FAB0FA /* AsyncAwait.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AsyncAwait.swift; sourceTree = "<group>"; };
148513951B9BD15100FAB0FA /* TaskBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TaskBuilder.swift; sourceTree = "<group>"; };
148513961B9BD15100FAB0FA /* Errors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Errors.swift; sourceTree = "<group>"; };
148513971B9BD15100FAB0FA /* MutuallyExclusiveTaskCondition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutuallyExclusiveTaskCondition.swift; sourceTree = "<group>"; };
148513981B9BD15100FAB0FA /* Task.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Task.swift; sourceTree = "<group>"; };
148513991B9BD15100FAB0FA /* TaskCondition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TaskCondition.swift; sourceTree = "<group>"; };
148513AB1B9BD19700FAB0FA /* TaskType+NetworkActivityIndicator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TaskType+NetworkActivityIndicator.swift"; sourceTree = "<group>"; };
148513AB1B9BD19700FAB0FA /* NetworkActivityIndicatorTaskObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkActivityIndicatorTaskObserver.swift; sourceTree = "<group>"; };
148513AD1B9BD38100FAB0FA /* LocationPermissionTaskCondition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationPermissionTaskCondition.swift; sourceTree = "<group>"; };
148513B01B9BD9A500FAB0FA /* FailableTaskType+Timeout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FailableTaskType+Timeout.swift"; sourceTree = "<group>"; };
148513B01B9BD9A500FAB0FA /* TimeoutTaskObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TimeoutTaskObserver.swift; sourceTree = "<group>"; };
14C2903F1BDE544B006F1BB3 /* TaskWaiter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TaskWaiter.swift; sourceTree = "<group>"; };
14E585BB1B7803EC003EC4DC /* AlecrimAsyncKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AlecrimAsyncKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
14E585BE1B7803EC003EC4DC /* AlecrimAsyncKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AlecrimAsyncKit.h; sourceTree = "<group>"; };
14E585C01B7803EC003EC4DC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -92,10 +100,14 @@
148513941B9BD15100FAB0FA /* Core */ = {
isa = PBXGroup;
children = (
148513951B9BD15100FAB0FA /* AsyncAwait.swift */,
148513981B9BD15100FAB0FA /* Task.swift */,
1413F62D1BDCAE8B001049D5 /* TaskType.swift */,
1413F62B1BDCAE56001049D5 /* TaskState.swift */,
148513951B9BD15100FAB0FA /* TaskBuilder.swift */,
14C2903F1BDE544B006F1BB3 /* TaskWaiter.swift */,
148513961B9BD15100FAB0FA /* Errors.swift */,
148513991B9BD15100FAB0FA /* TaskCondition.swift */,
1416E08C1BDC931A00F1EA73 /* TaskObserver.swift */,
148513971B9BD15100FAB0FA /* MutuallyExclusiveTaskCondition.swift */,
);
path = Core;
Expand All @@ -104,17 +116,17 @@
148513AA1B9BD19700FAB0FA /* Convenience Observers */ = {
isa = PBXGroup;
children = (
143045501BB7AB5900CD0AED /* TaskType+Activity.swift */,
147B5F361B9CFB0700F9F2CE /* TaskType+BackgroundTaskObserver.swift */,
148513AB1B9BD19700FAB0FA /* TaskType+NetworkActivityIndicator.swift */,
143045501BB7AB5900CD0AED /* ProcessInfoActivityTaskObserver.swift */,
147B5F361B9CFB0700F9F2CE /* ApplicationBackgroundTaskObserver.swift */,
148513AB1B9BD19700FAB0FA /* NetworkActivityIndicatorTaskObserver.swift */,
);
path = "Convenience Observers";
sourceTree = "<group>";
};
148513AF1B9BD9A500FAB0FA /* Additional Observers */ = {
isa = PBXGroup;
children = (
148513B01B9BD9A500FAB0FA /* FailableTaskType+Timeout.swift */,
148513B01B9BD9A500FAB0FA /* TimeoutTaskObserver.swift */,
);
path = "Additional Observers";
sourceTree = "<group>";
Expand Down Expand Up @@ -237,23 +249,27 @@
buildActionMask = 2147483647;
files = (
148513A11B9BD15100FAB0FA /* PhotosPermissionTaskCondition.swift in Sources */,
14C290401BDE544B006F1BB3 /* TaskWaiter.swift in Sources */,
1413F62C1BDCAE56001049D5 /* TaskState.swift in Sources */,
148513A01B9BD15100FAB0FA /* PassLibraryAvailableCondition.swift in Sources */,
148513A31B9BD15100FAB0FA /* RemoteNotificationPermissionTaskCondition.swift in Sources */,
148513A81B9BD15100FAB0FA /* TaskCondition.swift in Sources */,
147B5F371B9CFB0700F9F2CE /* TaskType+BackgroundTaskObserver.swift in Sources */,
143045511BB7AB5900CD0AED /* TaskType+Activity.swift in Sources */,
147B5F371B9CFB0700F9F2CE /* ApplicationBackgroundTaskObserver.swift in Sources */,
143045511BB7AB5900CD0AED /* ProcessInfoActivityTaskObserver.swift in Sources */,
1485139E1B9BD15100FAB0FA /* NegateTaskCondition.swift in Sources */,
148513A61B9BD15100FAB0FA /* MutuallyExclusiveTaskCondition.swift in Sources */,
148513B11B9BD9A500FAB0FA /* FailableTaskType+Timeout.swift in Sources */,
148513B11B9BD9A500FAB0FA /* TimeoutTaskObserver.swift in Sources */,
1413F62E1BDCAE8B001049D5 /* TaskType.swift in Sources */,
148513A21B9BD15100FAB0FA /* ReachabilityTaskCondition.swift in Sources */,
148513A71B9BD15100FAB0FA /* Task.swift in Sources */,
148513A51B9BD15100FAB0FA /* Errors.swift in Sources */,
148513A41B9BD15100FAB0FA /* AsyncAwait.swift in Sources */,
148513A41B9BD15100FAB0FA /* TaskBuilder.swift in Sources */,
148513AE1B9BD38100FAB0FA /* LocationPermissionTaskCondition.swift in Sources */,
1485139D1B9BD15100FAB0FA /* DelayTaskCondition.swift in Sources */,
1485139F1B9BD15100FAB0FA /* SilentTaskCondition.swift in Sources */,
1416E08D1BDC931A00F1EA73 /* TaskObserver.swift in Sources */,
14749B861B9C4DA300661E98 /* BooleanTaskCondition.swift in Sources */,
148513AC1B9BD19700FAB0FA /* TaskType+NetworkActivityIndicator.swift in Sources */,
148513AC1B9BD19700FAB0FA /* NetworkActivityIndicatorTaskObserver.swift in Sources */,
14749B841B9C437700661E98 /* EventStorePermissionTaskCondition.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -363,7 +379,7 @@
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 143;
CURRENT_PROJECT_VERSION = 149;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -385,7 +401,7 @@
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 143;
CURRENT_PROJECT_VERSION = 149;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// TimeoutTaskObserver.swift
// AlecrimAsyncKit
//
// Created by Vanderlei Martinelli on 2015-08-15.
// Copyright (c) 2015 Alecrim. All rights reserved.
//

import Foundation

public final class TimeoutTaskObserver: TaskObserver {

public init(timeout: NSTimeInterval) {
super.init()

self.taskWillStart { task in
if let task = task as? CancellableTaskType {
weak var weakTask = task

let when = dispatch_time(DISPATCH_TIME_NOW, Int64(timeout * Double(NSEC_PER_SEC)))

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) {
weakTask?.cancel()
}
}
}
}

}
Loading

0 comments on commit c2ab771

Please sign in to comment.