Skip to content

Instantly share code, notes, and snippets.

@godrm
Created March 26, 2018 06:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save godrm/3daf7d2c579f8353aae3b289ffcfb625 to your computer and use it in GitHub Desktop.
Save godrm/3daf7d2c579f8353aae3b289ffcfb625 to your computer and use it in GitHub Desktop.
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