You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There should be a way to cancel callbacks that have been scheduled. In some cases, it is known early that the callback won't be needed, and it would be useful to remove it so that objects can be GC'd.
In this example which implements a timeout using promises, we know immediately, when resolve() is called, that timeout function (which calls reject()) won't be needed. However, that function sticks around until 5 seconds has passed, and during that time it holds a reference to the environment e, which prevents e from being GC'd. It's only after the 5 seconds have passed that the callback fires, and reject() is called -- which in this case is a no-op because resolve() has already been called -- that e can be GC'd.
There should be a way to cancel callbacks that have been scheduled. In some cases, it is known early that the callback won't be needed, and it would be useful to remove it so that objects can be GC'd.
In this example which implements a timeout using promises, we know immediately, when
resolve()
is called, that timeout function (which callsreject()
) won't be needed. However, that function sticks around until 5 seconds has passed, and during that time it holds a reference to the environmente
, which preventse
from being GC'd. It's only after the 5 seconds have passed that the callback fires, andreject()
is called -- which in this case is a no-op becauseresolve()
has already been called -- thate
can be GC'd.Related:
rstudio/websocket#40 (comment)
Maybe it could return an ID like JavaScript's
setTimeout()
? Or perhaps a function that cancels the callback.The text was updated successfully, but these errors were encountered: