Combination of debugging in VS-code with delayed launch

I am trying to run several programs that need to communicate with each other in a debugger in VS code and create launch.json with a connection that launches each of the executable files. Programs run simultaneously and everyone tries to connect to the host at the same time. Is there any way in VS Code to explicitly set some time delay between the launch of each of the executable files, say, 250 ms?

{ "version": "0.2.0", "configurations": [ { "name": "Host", "type": "cppdbg", "request": "launch", "program": "/home/user/build/bin/host", "args": [], "stopAtEntry": false, "cwd": "/home/user/build/bin", "environment": [], "externalConsole": true, "linux": { "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } }, { "name": "Node A", "type": "cppdbg", "request": "launch", "program": "/home/user/build/bin/Node_A", "args": ["ArgA","ArgB","ArgC"], "stopAtEntry": false, "cwd": "/home/user/build/bin", "environment": [], "externalConsole": true, "linux": { "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } }, { "name": "Node B", "type": "cppdbg", "request": "launch", "program": "/home/user/build/bin/Node_B", "args": ["ArgA","ArgB","ArgC"], "stopAtEntry": false, "cwd": "/home/user/build/bin", "environment": [], "externalConsole": true, "linux": { "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } } ], "compounds": [ { "name": "System", "configurations": ["Host","Node A","Node B"] } ] } 
+14
debugging visual-studio-code
source share
1 answer

Yes, you can add a preliminary task that will sleep for x seconds.

Suppose you have a client and server on Node.js, and loading the database with the server takes longer, this causes problems with the client.

Client debugger delay on vscode will work the same on Mac OS X

First, create a task in the same folder as the launch.json file named tasks.json, which will create a shell command before launching the client.

 { // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "Sleepdelay", "type": "shell", "command": "sleep 6", "windows": { "command": "ping 127.0.0.1 -n 6 > nul" }, "group": "none", "presentation": { "reveal": "silent", "panel": "new" } } ] 

}

Add the following preliminary task to the launch.json file now to invoke the task.

 "configurations": [ { "type": "chrome", "request": "launch", "name": "Client", "url": "http://localhost:9090", "webRoot": "${workspaceFolder}/client/src", "breakOnLoad": true, "sourceMapPathOverrides": { "webpack:///./src/*": "${webRoot}/*" }, "preLaunchTask": "Sleepdelay" //"runtimeExecutable": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" }, { "type": "node", "request": "launch", "name": "Server", "program": "${workspaceFolder}/server/server.js", "envFile": "${workspaceFolder}/server/.env", "cwd": "${workspaceFolder}/server/" } ], "compounds": [ { "name": "Server/Client", "configurations": ["Server", "Client"] } ] 

The sleep command is available on Linux and MAC OS X. For Windows, just use this hack instead:

ping 127.0.0.1 -n 6> zero

Now you have an easy way to delay starting a client in front of the server.

0
source share

All Articles