README.md in futuroscope-0.0.2 vs README.md in futuroscope-0.0.3
- old
+ new
@@ -39,10 +39,11 @@
$ gem install futuroscope
## Usage
+### Simple futures
```Ruby
require 'futuroscope'
x = Futuroscope::Future.new{ sleep(1); 1 }
y = Futuroscope::Future.new{ sleep(1); 2 }
@@ -53,10 +54,33 @@
puts x + y + z
=> 6
```
+### Future map
+```Ruby
+require 'futuroscope'
+
+map = Futuroscope::Map.new([1, 2, 3]).map do |i|
+ sleep(1)
+ i + 1
+end
+
+puts map.first
+=> 2
+
+puts map[1]
+=> 3
+
+puts map.last
+=> 4
+
+# This action will actually only take 1 second.
+```
+
+### Convenience methods
+
If you don't mind polluting the `Kernel` module, you can also require
futuroscope's convenience `future` method:
```Ruby
require 'futuroscope/convenience'
@@ -66,9 +90,33 @@
z = future{ sleep(1); 3 }
puts x + y + z
=> 6
```
+
+Same for a map:
+
+```Ruby
+require 'futuroscope/convenience'
+
+items = [1, 2, 3].future_map do |i|
+ sleep(i)
+ i + 1
+end
+```
+
+## Considerations
+
+You should never add **side-effects** to a future. They have to be thought of
+like they were a local variable, with the only outcome that they're returning a
+value.
+
+You have to take into account that they really run in a different thread, so
+you'll be potentially accessing code in parallel that could not be threadsafe.
+
+If you're looking for other ways to improve your code performance via
+concurrency, you should probably deal directly with [Ruby's
+threads](http://ruby-doc.org/core-2.0/Thread.html).
## Ideas for the future
* Having a thread pool so you can limit maximum concurrency.