Created
February 21, 2022 21:59
-
-
Save drosenstark/3e6f7f3c0cbcd544d15d1f16ae136998 to your computer and use it in GitHub Desktop.
Extension for easy testing of async code
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
// Copyright 2022 Confusion Studios LLC | |
// by Dan Rosenstark | |
import Foundation | |
/// Extension on DispatchQueue? for Testing | |
/// If you don't have a DispatchQueue, run immediately (on current queue) | |
extension Optional where Wrapped : DispatchQueue { | |
public func asyncIfNotNil(execute block: @escaping ()->()) { | |
if let self = self { | |
self.async(execute: block) | |
} else { | |
// should only happen in DEBUG (for testing) | |
block() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment