Skip to content

Commit

Permalink
Don't bother spawning a new thread if there's only one item
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Dec 18, 2013
1 parent 009e3fa commit c01ea83
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/twitter/util.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
module Twitter
module Util
def self.threaded_map(enumerable)
enumerable.map { |object|
Thread.new { yield object }
}.map(&:value)
# Don't bother spawning a new thread if there's only one item
if enumerable.count == 1
enumerable.map { |object| yield object }
else
enumerable.map { |object| Thread.new { yield object } }.map(&:value)
end
end
end
end

0 comments on commit c01ea83

Please sign in to comment.