是说重新presents与可能性潜在延迟异步计算订阅其完成图案的惯用红宝石模拟?即沿东西.NET的行 System.Threading.Task 或Python 3.X concurrent.futures.future
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.
请注意,这并不一定意味着多线程 - 实际执行的未来对象将同样有可能使用调度的工作和取得的结果一些其他的方式,而且是出了问题的范围。该问题涉及严格遵守是psented对象的用户$ P $的API。
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.
推荐答案我不知道香草红宝石,但EventMachine的有deferrables.
I am not sure about vanilla Ruby, but EventMachine has deferrables.
此外,检查this文章。
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}" } }更多推荐
任务/未来的Ruby
发布评论