Parallel step is not parallel

Wappler 5.0.3
NodeJS

Request took 2 seconds instead of 1. The Wait steps were supposed to run in parallel, right? It looks like they’re running sequentially

Edit: My debugging attempt revealed the following:
options.exec is not an array, look:

{
  steps: [
    {
      name: '',
      module: 'core',
      action: 'group',
      options: [Object],
      output: true
    },
    {
      name: '',
      module: 'core',
      action: 'group',
      options: [Object],
      output: true
    }
  ]
}

It’s an object that contains the element “steps”, which is an array

My fix that seems to work, but Patrick needs to double-check:

    parallel: async function(options, name) {
        var data = {};

        if (name) {
            let parentData = this.data;
            this.data = {};
            if (Array.isArray(options.exec.steps)) {
                await Promise.all(options.exec.steps.map(exec => this.exec(exec, true)));
            } else {
                await this.exec(options.exec, true);
            }
            data = this.data;
            this.data = parentData;
        } else {
            if (Array.isArray(options.exec)) {
                await Promise.all(options.exec.map(exec => this.exec(exec, true)));
            } else {
                await this.exec(options.exec, true);
            }
        }

        return data;
    },
2 Likes

The options.exec can have 3 different structures: a single action object, an array of action objects or an object with a steps array that contains the action objects.

Changed the code to:

    parallel: async function(options, name) {
        var data = {};
        let actions = options.exec.steps || options.exec;

        if (name) {
            let parentData = this.data;
            this.data = {};
            if (Array.isArray(actions)) {
                await Promise.all(actions.map(exec => this.exec(exec, true)));
            } else {
                await this.exec(actions, true);
            }
            data = this.data;
            this.data = parentData;
        } else {
            if (Array.isArray(actions)) {
                await Promise.all(actions.map(exec => this.exec(exec, true)));
            } else {
                await this.exec(actions, true);
            }
        }

        return data;
    },

Fixed in Wappler 5.0.4

This topic was automatically closed after 32 hours. New replies are no longer allowed.