const wait = ms => new Promise(resolve => setTimeout(resolve, ms)); /** Serialize J-Link GDB Server starts so two probes on USB do not race. */ let spawnChain = Promise.resolve(); const withGdbSpawn = async fn => { const run = spawnChain.then(() => fn()); spawnChain = run .then(() => wait(450)) .catch(() => wait(450)); return run; }; module.exports = { withGdbSpawn };