Skip to content

Commit

Permalink
Avoid observe overhead for Future#map
Browse files Browse the repository at this point in the history
Out of the combinators, this is the only case that does not rely on
pre-existing futures, auto detection, or rescuing errors, so the extra
verbosity seems like a reasonable trade-off.
  • Loading branch information
grddev committed Nov 5, 2014
1 parent 6eb6131 commit 6475a0d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/ione/future.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,13 @@ def map(value=nil, &block)
else
f = CompletableFuture.new
on_complete do |v, e|
f.observe(map(value, &block))
if e
f.fail(e)
elsif block.nil?
f.resolve(value)
else
f.try(v, &block)
end
end
f
end
Expand Down

0 comments on commit 6475a0d

Please sign in to comment.