Skip to content

Commit 54694a7

Browse files
committed
Fix memory leak in AWAIT_ON_READY
The original implementation used _finally(), which created multiple intermediate promise objects. These weren't settled until the event loop stopped, creating a memory leak and significant delay on stop. Simplified AWAIT_ON_READY to directly register callbacks without intermediate objects, eliminating the leak while maintaining correct functionality. This will also be quicker. Fixes #2220
1 parent f9b7f72 commit 54694a7

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/Mojo/Promise.pm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ sub AWAIT_NEW_FAIL { _await('reject', @_) }
3737
sub AWAIT_ON_CANCEL { }
3838

3939
sub AWAIT_ON_READY {
40-
shift->_finally(0, @_)->catch(sub { });
40+
my ($self, $cb) = @_;
41+
push @{$self->{resolve}}, $cb;
42+
push @{$self->{reject}}, $cb;
4143
}
4244

4345
sub AWAIT_WAIT {

0 commit comments

Comments
 (0)