Created
March 26, 2018 06:38
-
-
Save godrm/3daf7d2c579f8353aae3b289ffcfb625 to your computer and use it in GitHub Desktop.
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
import Foundation | |
class ReadValue { | |
var successClosure : ((String)->())? = nil | |
var value : String = "" { | |
didSet { | |
if let closure = successClosure { | |
closure(value) | |
} | |
} | |
} | |
func asyncRead( completed:@escaping (String)->() ) { | |
successClosure = completed | |
DispatchQueue.global().async { | |
self.value = readLine() ?? "" | |
} | |
} | |
} | |
var read = ReadValue() | |
read.asyncRead { (readValue) in | |
print(readValue) | |
exit(1) | |
} | |
while(true) { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment