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.
The thread gem might be of interest. You can make a thread-pool that processes stuff in the background. The gem also support a whole lot of other features like future, delay etc. Have a look at the github repo.
It appears to work with a wide range of ruby versions, not just 1.9+, which is why I use this.