0

i am interfacing some existing nodejs code (particle cli) for factory testing. got all to work separately but have some last remaining issue running the "commands" sequentially which seems trivial?!

my code below. the "particle identify" command works and the "particle flash" command works but together they do not as "particle flash" starts while "particle identify" is processing

i tried "await" but that gives "SyntaxError: await is only valid in async function". ".then" works but to make that work i have to nest all the commands which makes it unreadable?

anyone any suggestions?

thanks frank

"use strict"
  
const SerialCommands = require('particle-cli/dist/cmd/serial');
const FlashCommand = require('particle-cli/dist/cmd/flash');

global.verboseLevel = 1;

// command is found in cli/serial.js
// args are found in cmd/serial.js

// particle identify
new SerialCommands().identifyDevice({port: undefined});

// particle flash
new FlashCommand().flash('p1-bootloader@1.5.2+lto.bin', 'p1-bootloader@1.5.2+lto.bin', [], {usb: false, serial: true, factory: false, force: false, target: undefined, port: undefined, yes: true});
Giovanni Esposito
  • 10,696
  • 1
  • 14
  • 30
frb
  • 53
  • 5

1 Answers1

1

Wrap your code in an async function and immediately call it:

;(async function() {
  // your code here
})() 
Tsvetan Ganev
  • 8,246
  • 4
  • 26
  • 43
  • thanks but still confused: when i just put e.g. console.log in the function it works but with my code it does not?? – frb Jul 20 '20 at 09:09
  • 1
    ahhh... put all "commands" in the function with await works! thanks1 – frb Jul 20 '20 at 09:17