frb
frb

Reputation: 53

sequential processing in nodejs

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});

Upvotes: 0

Views: 118

Answers (1)

Tsvetan Ganev
Tsvetan Ganev

Reputation: 8856

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

;(async function() {
  // your code here
})() 

Upvotes: 1

Related Questions