Last active
July 9, 2019 22:08
-
-
Save standinga/ad8e4787c38d6eecfba95d559fe7529d to your computer and use it in GitHub Desktop.
function parsing into to string after defined delay time
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
func fetchData(_ data: Int, delay: Double, completionHandler: @escaping (String)->()) { | |
DispatchQueue.main.asyncAfter(deadline: .now() + delay) { | |
completionHandler("\(data)") | |
} | |
} | |
var text = "" | |
for i in 0..<20 { | |
fetchData(i, delay: Double.random(in: 0...0.2)) { | |
text += "\($0) - " | |
} | |
} | |
print("text:", text) | |
RunLoop.current.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment