Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug async/await in visual studio code?

Tags:

I want to debug js file that includes async/await in visual studio code,but it reminds me that vscode doesn't support it. What can I do to make vscode support async/await?

like image 411
JimZhang Avatar asked Jun 12 '16 05:06

JimZhang


People also ask

How do I debug async code in Visual Studio?

Double-clicking an active or awaiting task shows the async call stack in the Call Stack window. To understand which thread is running a specific task, you can swap between the Parallel Threads and Parallel Tasks windows. You can do this by right-clicking and selecting Go To Thread in the context menu.

Can we debug async method?

Debug asynchronous code Debugging asynchronous code is a challenge because the tasks are often scheduled in one thread and executed in another. Every thread has its own stacktrace, making it difficult to figure out what happened before the thread started.

Can I debug C# in Visual Studio code?

To start debugging, select F5, or choose the Debug Target button in the Standard toolbar, or choose the Start Debugging button in the Debug toolbar, or choose Debug > Start Debugging from the menu bar. The app starts and the debugger runs to the line of code where you set the breakpoint.

How do I debug async code in Visual Studio?

In the last async debugging blog post, we explored several tools in Visual Studio to help you debug your async code. One of the tools we discussed was the Parallel Stacks window for Tasks (or Parallel Tasks), a tool that provides task and thread information while debugging.

What is the use of await and async in web applications?

The additions of the Task type, async, and await in .NET provide an extra layer of abstraction, which enable you to write responsive applications but also make it harder to navigate through and understand the status of each awaiting or active task while debugging.

How to analyze async code?

Async code can be analyzed through a parallel task, parallel watch, parallel threads, or the tasks window. Use all these tools together to analyze async code thoroughly.

How to show async method after pressing F11 in debug mode?

1) press ctrl+p in vscode and type ">launch", select "open launch.json" 2) after opening "launch.json", just add to configuration section : After these steps you can see your real async method after pressing F11 in debug mode. Show activity on this post.


2 Answers

As now, in 2019, latest VSCode supporting async/await debug, just would like to share solution to prevent vscode to "Step into" (by f11) into async/await method through the "async_hooks.js" and "inspector_async_hook.js" files during debug nodejs applications.

Howto :

1) press ctrl+p in vscode and type ">launch", select "open launch.json"

2) after opening "launch.json", just add to configuration section :

"skipFiles": [     "inspector_async_hook.js",     "async_hooks.js"   ] 

or some more generic version :

"skipFiles": ["<node_internals>/**"] 

So you final json should looks something like here:

{   "version": "0.2.0",   "configurations": [     {       "type": "node",       "request": "launch",       "name": "Launch Program",       "program": "${workspaceFolder}\\index.js",       "skipFiles": ["<node_internals>/**"]     }   ] } 

After these steps you can see your real async method after pressing F11 in debug mode.

like image 105
Nigrimmist Avatar answered Sep 18 '22 17:09

Nigrimmist


Currently you can use async/await in Node.js 7 or latest using --harmony flag, you can configure your vscode debugger (launch.json) in the following way to run and debug async/await Nodejs code.

{     "version": "0.2.0",     "configurations": [         {             "type": "node",             "request": "launch",             "name": "Node 7 Async/Await",             "program": "${workspaceRoot}/main.js",             "cwd": "${workspaceRoot}",             "runtimeArgs": [                 "--harmony",                 "--no-deprecation"             ]         },         {             "type": "node",             "request": "attach",             "name": "Attach to Process",             "port": 5858         }     ] } 

You must change the program by your startup script file.

like image 42
Gonzalo Bahamondez Avatar answered Sep 16 '22 17:09

Gonzalo Bahamondez