Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: bry4n/parallel2
base: ed0488d295
...
head fork: bry4n/parallel2
compare: 325f6308c2
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 29 additions and 2 deletions.
  1. +18 −0 examples/sleep.rb
  2. +11 −2 lib/parallel2.rb
18 examples/sleep.rb
View
@@ -0,0 +1,18 @@
+$:.unshift "lib"
+
+require 'parallel2'
+
+list = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]
+
+Parallel.each(list) do |i|
+ sleep i
+ puts "#{i} fired!"
+end
+
+data = Parallel.map(list) do |i|
+ sleep i
+ puts "#{i} fired!"
+ i
+end
+
+p data
13 lib/parallel2.rb
View
@@ -5,18 +5,27 @@ class Parallel
def self.each(collection, &block)
klass = new(collection, &block)
- klass.parallelized_each(&block)
+ klass.parallelized_each
collection
end
+ def self.map(collection, &block)
+ klass = new(collection, &block)
+ klass.parallelized_map
+ end
+
def initialize(collection, &block)
@collection = collection
@block = block
end
- def parallelized_each(&block)
+ def parallelized_each
futures.each(&:value)
end
+
+ def parallelized_map
+ futures.map(&:value)
+ end
def futures
@futures ||= @collection.map do |item|

No commit comments for this range

Something went wrong with that request. Please try again.