Skip to content

Commit

Permalink
Change api for ui and delayCall functions. Add delayed closure call.
Browse files Browse the repository at this point in the history
  • Loading branch information
MadGeorge committed Jan 11, 2017
1 parent 819ef65 commit f853eb1
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions GobalFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,40 @@ func L(_ key: String) -> String {
return NSLocalizedString(key, comment: "")
}

/// Run closure in background
/**
Run closure in background

Do not call UI on execution!
*/
func future(closure: @escaping ()->()) {
let backQueue = DispatchQueue.global()
backQueue.async(execute: closure)
}

/// Run closure after delay on main thread
func delayCall(delayInSeconds: Double, closure: @escaping()->()) {
/**
Run closure in background after delay

Do not call UI on execution!
*/
func delaiedFuture(_ delayInSeconds: Double, closure: @escaping ()->()) {
let delay = DispatchTime.now() + delayInSeconds
let backQueue = DispatchQueue.global()
backQueue.asyncAfter(deadline: delay, execute: closure)
}

/**
Run closure after delay on main thread

Safe for UI calls
*/
func delayCall(_ delayInSeconds: Double, closure: @escaping()->()) {
let delay = DispatchTime.now() + delayInSeconds
DispatchQueue.main.asyncAfter(deadline: delay) {
closure()
}
}

/// Run any closure on main thread explisitly
func ui(closure: @escaping ()->()){
func ui(_ closure: @escaping ()->()){
DispatchQueue.main.async(execute: closure)
}

0 comments on commit f853eb1

Please sign in to comment.