Skip to content

Commit 778f6fa

Browse files
committed
Fix reference leak in constructor
1 parent fa637f4 commit 778f6fa

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/concurrent/edge/future.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -999,11 +999,16 @@ class InnerPromise < AbstractPromise
999999
# @abstract
10001000
# @!visibility private
10011001
class BlockedPromise < InnerPromise
1002+
def self.new(*args, &block)
1003+
promise = super(*args, &block)
1004+
promise.blocked_by.each { |f| f.add_callback :pr_callback_notify_blocked, promise }
1005+
promise
1006+
end
1007+
10021008
def initialize(future, blocked_by_futures, countdown)
10031009
super(future)
10041010
initialize_blocked_by(blocked_by_futures)
10051011
@Countdown = AtomicFixnum.new countdown
1006-
@BlockedBy.each { |f| f.add_callback :pr_callback_notify_blocked, self }
10071012
end
10081013

10091014
# @api private
@@ -1064,10 +1069,9 @@ def on_completable(done_future)
10641069
class BlockedTaskPromise < BlockedPromise
10651070
def initialize(blocked_by_future, default_executor, executor, &task)
10661071
raise ArgumentError, 'no block given' unless block_given?
1072+
super Future.new(self, default_executor), blocked_by_future, 1
10671073
@Executor = executor
10681074
@Task = task
1069-
# has to be after @Executor and @Task is set
1070-
super Future.new(self, default_executor), blocked_by_future, 1
10711075
end
10721076

10731077
def executor

0 commit comments

Comments
 (0)