Skip to content

Commit

Permalink
concurrent/cached_value: Avoid computing twice
Browse files Browse the repository at this point in the history
Also, clear `@computation` after we obtained the value, as we no longer
need it.

Refs #300
  • Loading branch information
glebm committed Sep 18, 2018
1 parent ef94e1a commit d81b34e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/i18n/tasks/concurrent/cached_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ def initialize(&computation)
def get
return @result unless @result == NULL
@mutex.synchronize do
@result = @computation.call
if @result == NULL
@result = @computation.call
@computation = nil
end
end
@result
end
end
end

0 comments on commit d81b34e

Please sign in to comment.