Starting my learning curve on NodeJS, I am trying to call a sequence of functions using async.series. Each function is a command line that is called remotely using REST.
function TestStorageDeviceBasic()
{
scenario = [
'cmdline1',
'cmdline2'
];
tasks = [];
scenario.forEach(command => { tasks.push(RunCommand(sessionId,command));});
async.series(tasks);
}
function RunCommand(sessionId, cmdLine)
{
var options = {
uri: `http://${domain}/api/v1/commands`,
method: 'POST',
json: {
'session-id' : `${sessionId}`,
'command-line': `${cmdLine}`
}
};
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
log.debug(`\"${cmdLine}\" status code successful`)
log.debug(body);
}
else
log.error(`\"${cmdLine}\" status code failed`,error);
});
}
I am getting a few problems even though the RunCommand function seems to be called.
(node:21008) UnhandledPromiseRejectionWarning: Error: expected a function
at wrapAsync (C:\work\MyJavascriptProject\my_sample\node_modules\async\dist\async.js:198:50)
at C:\work\MyJavascriptProject\my_sample\node_modules\async\dist\async.js:2952:13
Why RunCommand is not considered a function?
RunCommandand pushing the result of the function into tasks. The result ofRunCommandis not a function. You might try using.bind()to make a function with the captured parameters.