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
In the section "Promises", there is a exercise named "Empty Promises". I tried to fill the blanks, and I was able to get the desired result. However, the execution time is much faster than expected. It seems that the setTimeout is returning instantly. Here is my code.
After some digging, I found that the problem seems to be in the invocation of resolve(someInteger). When calling setTimeout, this part will be evaluated, thus the promises will be returned immediately. One possible fix is using Function.Prototype.bind to wrap, as shown below:
The exercise only allows the blanks to be filled, but I can not find a way to resulting in the desired execution (wait up to 8 sec) without changing other code. Thus I doubt that there might possibly be an issue here.
In the section "Promises", there is a exercise named "Empty Promises". I tried to fill the blanks, and I was able to get the desired result. However, the execution time is much faster than expected. It seems that the
setTimeout
is returning instantly. Here is my code.After some digging, I found that the problem seems to be in the invocation of
resolve(someInteger)
. When callingsetTimeout
, this part will be evaluated, thus the promises will be returned immediately. One possible fix is using Function.Prototype.bind to wrap, as shown below:The exercise only allows the blanks to be filled, but I can not find a way to resulting in the desired execution (wait up to 8 sec) without changing other code. Thus I doubt that there might possibly be an issue here.
Source: javascript - How can I pass a parameter to a setTimeout() callback? - Stack Overflow
The text was updated successfully, but these errors were encountered: