-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't bother spawning a new thread if there's only one item
- Loading branch information
Showing
1 changed file
with
6 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |