17

await Promise.resolve(1) in chrome devtools (chrome version 70.0.3538.77) resolves to:

  • 1 when script execution is not paused
  • Promise <pending> when script execution is paused

How to resolve it to 1 when script execution is paused

enter image description here

N.B.

this question continues chrome debugger promises dont resolve while paused? to find the exact way to resolve promises when chrome is paused

srghma
  • 4,770
  • 2
  • 38
  • 54
  • 2
    `console.log(await Promise.resolve(1))` – Keith Dec 19 '18 at 14:18
  • 1
    @Keith, no, it resolves to `Promise ` too – srghma Dec 19 '18 at 14:21
  • @Keith, here is the reproduction https://imgur.com/a/oDDDet9 – srghma Dec 19 '18 at 14:23
  • No it resolves to 1, what your seeing in the console is the promise been returned, not it's resolved value,.. If and when you un-pause the debugger, you will see the value `1` in the console output. You can't get 1 while paused, that's impossible, because it hasn't yet happened. – Keith Dec 19 '18 at 14:27
  • Aren't you basically asking how to continue executing a script, while script execution is paused? – Daniel Beck Dec 19 '18 at 14:28
  • @Keith you didnt mention that I should unpause execution, this doesnt work for me – srghma Dec 19 '18 at 14:29
  • 1
    @DanielBeck I dont want to execute the script, I want to execute async functions while script is paused (think about it, I can calculate ordinary functions while paused, but not async calls, why?) – srghma Dec 19 '18 at 14:29
  • `yes, exactly ` In Chrome under Sources, on the right hand side are your `pause / run / step over` debugging tools,. I think that's what your looking for. – Keith Dec 19 '18 at 14:32
  • @Keith, no, this doesnt work for me (I have modified my comment above) – srghma Dec 19 '18 at 14:34
  • `but not async calls, why?`, async calls run in the next tick, because you have paused there is never a next tick,. sync calls inside the console of course don't require a next tick. – Keith Dec 19 '18 at 14:38
  • @Keith so, it's impossible? – srghma Dec 19 '18 at 14:42
  • 2
    Yes,. JS is single threaded, this means it has 1 single message loop. When you pause, it will pause the message loop. If it didn't it would make debugging even harder. What problem are you trying to solve, I wonder if this is an X/Y problem. – Keith Dec 19 '18 at 14:45
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/185492/discussion-between-srghma-and-keith). – srghma Dec 19 '18 at 14:48

1 Answers1

2

Answer - it's not possible to make promises resolve WHEN js is paused in chrome, even promises that are created in console

(js is single threaded)

srghma
  • 4,770
  • 2
  • 38
  • 54