Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

253
Views
Async.parallelLimit Function Executing Callback Function Before Tasks

I am attempting to setup some newman test runs in parallel for different environments, and then create a Jira ticket via API request once all are completed with the results. However, when I use the ansync.parallelLimit function for that task, I find that the jira ticket gets created without any of the information from the test runs.

A simplified version of the process is this:

var async = require('async');
const path = require('path');
const newman = require('newman');
config = require(path.join(__dirname, 'config.json'));

const jira_data = [];

var create_ticket = function(err, results){
    console.log("Run Complete");
};

var test_run = async() =>{
  newman.run({
    collection: path.join(__dirname, 'Test.postman_collection.json'),
    reporters: ['htmlextra'],
    reporter: {
      htmlextra : { export : path.join(__dirname, '/reports/Test.html')}
    },})
}

var commands = [test_run,test_run,test_run,test_run];

async.parallelLimit(commands,4, (err, results) => {
  console.log("Run Complete");
  console.log(results);
});

That will result in the following output, indicating create_ticket was executed before anything else:

Run Complete
Using htmlextra version 1.22.3
Using htmlextra version 1.22.3
Using htmlextra version 1.22.3
Using htmlextra version 1.22.3
Created the htmlextra report.
Created the htmlextra report.
Created the htmlextra report.
Created the htmlextra report.

Alternatively, I can make test_run a function instead of async, like this:

var async = require('async');
const path = require('path');
const newman = require('newman');

const jira_data = [];

var create_ticket = function(err, results){
    console.log("Test Run Complete");
};

var test_run = function() {
  newman.run({
    collection: path.join(__dirname, 'Test.postman_collection.json'),
    reporters: ['htmlextra'],
    reporter: {
      htmlextra : { export : path.join(__dirname, '/reports/Test.html')}
    },}).on('request', function(err, results) {
      console.log("Hello");
    })
}

var commands = [test_run, test_run, test_run, test_run];

async.parallelLimit(commands, 4, create_ticket);

But now, create ticket doesn't run at all:

Using htmlextra version 1.22.3
Using htmlextra version 1.22.3
Using htmlextra version 1.22.3
Using htmlextra version 1.22.3
Hello
Hello
Hello
Hello
Created the htmlextra report.
Created the htmlextra report.
Created the htmlextra report.
Created the htmlextra report.

After spending more time than I care to admit playing with different combinations of variable types, argument passing, and other fixes, I am completely stumped. Any help at all would be greatly appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to pass and call a callback into test_run to complete the asynchronous task.

var test_run = function(callback) {
  newman.run({
    collection: path.join(__dirname, 'Test.postman_collection.json'),
    reporters: ['htmlextra'],
    reporter: {
      htmlextra : { export : path.join(__dirname, '/reports/Test.html')}
    },}).on('request', function(err, results) {
      console.log("Hello");
      callback(null);
    })
}

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!