Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize combinators for resolved cases #33

Merged
merged 1 commit into from
Oct 27, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/ione/future.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ def all(*futures)
end
if futures.count == 0
resolved([])
elsif (failed = futures.find { |f| f.respond_to?(:failed?) && f.failed? })
failed
else
CombinedFuture.new(futures)
end
Expand All @@ -231,6 +233,7 @@ def after(*futures)
if futures.size == 1 && (fs = futures.first).is_a?(Enumerable)
*futures = *fs
end
futures.reject! { |f| f.respond_to?(:resolved?) && f.resolved? }
if futures.count == 0
ResolvedFuture::NIL
elsif futures.count == 1
Expand Down Expand Up @@ -262,7 +265,9 @@ def first(*futures)
futures = fs
end
if futures.count == 0
resolved
ResolvedFuture::NIL
elsif (done = futures.find { |f| f.respond_to?(:resolved?) && f.resolved? })
done
else
FirstFuture.new(futures)
end
Expand Down