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('[email protected]+lto.bin', '[email protected]+lto.bin', [], {usb: false, serial: true, factory: false, force: false, target: undefined, port: undefined, yes: true});
2

1 Answer 1

1

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

;(async function() {
  // your code here
})() 
Sign up to request clarification or add additional context in comments.

2 Comments

thanks but still confused: when i just put e.g. console.log in the function it works but with my code it does not??
ahhh... put all "commands" in the function with await works! thanks1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.