What is the idiomatic Ruby analog of a pattern that represents a potentially deferred asynchronous computation with the possibility to subscribe to its completion? i.e. something along the lines of .NET System.Threading.Task
, or Python 3.x concurrent.futures.future
.
Note that this does not necessarily imply multithreading - the actual implementation of the "future" object would just as likely use some other way of scheduling the work and obtaining result, and is out of scope of the question. The question concerns strictly with the API that is presented to the user of the object.
I am not sure about vanilla Ruby, but EventMachine has deferrables.
Also, check out this article.
EM.run {
detector = LanguageDetector.new("Sgwn i os yw google yn deall Cymraeg?")
detector.callback { |lang| puts "The language was #{lang}" }
detector.errback { |error| puts "Error: #{error}" }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With