调用 Promise 的 then 函数花费太多时间

Sri*_*man 6 javascript react-native fetch-api

我正在使用 fetch API 来调用 React Native 应用程序中的服务器查询。then但是,我的应用程序在收到服务器的响应后需要 50 秒才能调用函数。我是否犯了任何错误,或者 Promise 运行速度是否非常慢?

fetch(url, {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      body: bodyContent
    }.then((responseText) =>  {
        console.log(responseText);
        responseText.json().then(function(response){
             console.log(response);
        });
    });
Run Code Online (Sandbox Code Playgroud)

response50 秒后打印在日志中responseText

更新:刚刚发现承诺responseText.json()只有在我再次点击屏幕后才会执行。这个问题很奇怪。

Sri*_*man 6

最后,我找到了这个问题的解决方案。正是因为Chrome Debugging. 如果我停止 chrome 调试,它工作正常。如果 Chrome 调试器正在运行,我必须点击屏幕才能获取返回值。因此,如果您正在运行 chrome 调试器,请忽略此延迟。