Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement