Are JavaScript forever-pending promises bad?

前端 未结 2 1426
盖世英雄少女心
盖世英雄少女心 2020-12-06 12:10

Say I have a promise called myProm, and say I have success and error handlers called onSuccess and onError.

Whenever my promis

2条回答
  •  情深已故
    2020-12-06 12:43

    There should be no side effect. It would be a browser bug if a non-referenced Promise in whatever state is keeping resources.

    Just make sure you don't keep any reference to the Promise object and you'll be fine.

    Beware that certain APIs such as setTimeout will keep a reference to the closure up to the timeout value. This means that if you have a long timeout, like the 10s one, you should clear it as soon as you don't need it anymore. Otherwise your code can call thousands of setTimeout within 10s, and each of them will keep a reference to the closure, which in your case will reference the Promise.

提交回复
热议问题