Last active
          September 27, 2019 13:49 
        
      - 
      
- 
        Save brocoo/290d53dd3404b9daed7c to your computer and use it in GitHub Desktop. 
    Delay the execution of a given closure on the main queue
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | public func delay(time: Double, completion: () -> Void) { | |
| let ms = dispatch_time(DISPATCH_TIME_NOW, Int64(time * Double(NSEC_PER_SEC))) | |
| dispatch_after(ms, dispatch_get_main_queue()) { | |
| () -> Void in | |
| completion() | |
| } | |
| } | |
| public func delay(time: Double) -> (()->Void) -> Void { | |
| return { | |
| (closure) -> Void in | |
| let ms = dispatch_time(DISPATCH_TIME_NOW, Int64(time * Double(NSEC_PER_SEC))) | |
| dispatch_after(ms, dispatch_get_main_queue()) { | |
| () -> Void in | |
| closure() | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment