Created
March 4, 2016 23:09
-
-
Save shaps80/0e3232a3dfb4bf7d4435 to your computer and use it in GitHub Desktop.
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
import Foundation | |
/** | |
* Simple GCD Wrapper | |
*/ | |
public struct Queue { | |
public typealias TimeInterval = NSTimeInterval | |
public static let Main = Queue(queue: dispatch_get_main_queue()); | |
public static let Default = Queue(queue: dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) | |
public static let Background = Queue(queue: dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)) | |
public static let High = Queue(queue: dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)) | |
public static let Low = Queue(queue: dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0)) | |
public private(set) var queue: dispatch_queue_t | |
public init(queue: dispatch_queue_t = dispatch_queue_create(NSBundle.mainBundle().bundleIdentifier! + ".queue", DISPATCH_QUEUE_SERIAL)) { | |
self.queue = queue | |
} | |
public func after(interval: NSTimeInterval, block: () -> Void) { | |
let dispatchTime = dispatch_time(DISPATCH_TIME_NOW, Int64(interval * NSTimeInterval(NSEC_PER_SEC))) | |
dispatch_after(dispatchTime, queue, block) | |
} | |
public func async(block: () -> Void) { | |
dispatch_async(queue, block) | |
} | |
public func sync(block: () -> Void) { | |
dispatch_sync(queue, block) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment