Why is my promise returning undefined?

前端 未结 2 1865
感情败类
感情败类 2020-12-19 23:06

Background

I am trying to make a function that delays the execution of asynchronous functions by X ms.

For the purposes of this demonstration, the followi

2条回答
  •  忘掉有多难
    2020-12-19 23:29

    Here's your problem:

            setTimeout(anUrl => {
                return new Promise( fulfil => {
                    fulfil(asyncMock(anUrl));
                });
            }, throttleMs, url);
    

    What you're doing here is you return a promise from the setTimeout callback. The return value of functions run by setTimeout are ignored so no one will get that value.

提交回复
热议问题