Skip to content

Commit 86fd08e

Browse files
committed
do not call touch when completed, saves CAS
1 parent da530a8 commit 86fd08e

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

lib/concurrent/edge/promises.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,6 @@ def touch
498498
self
499499
end
500500

501-
alias_method :needed, :touch
502-
503501
# @!macro [new] promises.touches
504502
# Calls {AbstractEventFuture#touch}.
505503

@@ -512,7 +510,6 @@ def touch
512510
# @return [Future, true, false] self implies timeout was not used, true implies timeout was used
513511
# and it was completed, false implies it was not completed within timeout.
514512
def wait(timeout = nil)
515-
touch
516513
result = wait_until_complete(timeout)
517514
timeout ? result : self
518515
end
@@ -657,7 +654,7 @@ def promise
657654

658655
# For inspection.
659656
# @!visibility private
660-
def touched
657+
def touched?
661658
@Touched.value
662659
end
663660

@@ -687,6 +684,8 @@ def add_callback(method, *args)
687684
def wait_until_complete(timeout)
688685
return true if completed?
689686

687+
touch
688+
690689
@Lock.synchronize do
691690
begin
692691
unless completed?
@@ -838,7 +837,6 @@ def failed?(state = internal_state)
838837
# @!macro promises.param.timeout
839838
# @return [Object, nil] the value of the Future when successful, nil on timeout or failure.
840839
def value(timeout = nil)
841-
touch
842840
internal_state.value if wait_until_complete timeout
843841
end
844842

@@ -850,7 +848,6 @@ def value(timeout = nil)
850848
# @!macro promises.param.timeout
851849
# @return [Exception, nil] nil on timeout or success.
852850
def reason(timeout = nil)
853-
touch
854851
internal_state.reason if wait_until_complete timeout
855852
end
856853

@@ -862,14 +859,12 @@ def reason(timeout = nil)
862859
# @return [Array(Boolean, Object, Exception), nil] triplet of success?, value, reason, or nil
863860
# on timeout.
864861
def result(timeout = nil)
865-
touch
866862
internal_state.result if wait_until_complete timeout
867863
end
868864

869865
# @!macro promises.method.wait
870866
# @raise [Exception] {#reason} on failure
871867
def wait!(timeout = nil)
872-
touch
873868
result = wait_until_complete!(timeout)
874869
timeout ? result : self
875870
end
@@ -878,7 +873,6 @@ def wait!(timeout = nil)
878873
# @return [Object, nil] the value of the Future when successful, nil on timeout.
879874
# @raise [Exception] {#reason} on failure
880875
def value!(timeout = nil)
881-
touch
882876
internal_state.value if wait_until_complete! timeout
883877
end
884878

0 commit comments

Comments
 (0)