小编L. *_*ger的帖子

使用 async/await 并发启动

我以为我对 async await 有很好的理解,直到我尝试了这个:

const promise1 = new Promise((resolve, reject) => {
  setTimeout(() => resolve('what'), 10000);
});

const promise2 = new Promise((resolve, reject) => {
  setTimeout(() => resolve('?'), 15000);
});

async function asyncTest() {
  console.time();
  const p1 = await promise1;

  if (p1 === 'what') {
    var p2 = await promise2;
  }

  console.log(p1, p2);
  console.timeEnd();
}

asyncTest()
Run Code Online (Sandbox Code Playgroud)

15000 毫秒后,asyncTest正在记录p1& p2。如果取而代之的是promise1promise2转换为返回这些承诺的函数,则执行时间为 25000 毫秒。我不知道是怎么回事。有人能解释一下吗?

javascript asynchronous async-await

6
推荐指数
1
解决办法
541
查看次数

使用 VSCode Chrome 调试器调试 Electron 渲染过程

设置角度 + 电子调试配置,它正在缓慢但肯定地粉碎我的灵魂。出于某种原因,渲染过程中没有击中断点(VSCode 显示错误Breakpoint ignored because generated code not found (source map problem?)")。

我的调试配置看起来像这样(完整的回购在这里):

// .vscode/launch.json
{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Electron: Main",
      "protocol": "inspector",
      // Prelaunch task compiles main.ts for Electron & starts Angular dev server.
      "preLaunchTask": "Build: All",
      "cwd": "${workspaceFolder}",
      "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
      "runtimeArgs": ["--remote-debugging-port=9223", "--serve", "."],
      "windows": {
        "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
      }
    },
    {
      "name": "Electron: Renderer",
      "type": "chrome",
      "request": "attach",
      "port": 9223,
      "webRoot": "${workspaceFolder}",
      "timeout": 30000,
      "urlFilter": "http://localhost:4200/*", …
Run Code Online (Sandbox Code Playgroud)

debugging electron visual-studio-code angular vscode-debugger

5
推荐指数
1
解决办法
769
查看次数