This repository has been archived by the owner on Feb 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,050 additions
and
909 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
Source/AlecrimAsyncKit/Additional Observers/FailableTaskType+Timeout.swift
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
Source/AlecrimAsyncKit/Additional Observers/TimeoutTaskObserver.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.