lib/concurrent/index.js
function executeConcurrent(client, query, parameters, options) {
  if (!client) {
    throw new TypeError('Client instance is not defined');
  }

  if (typeof query === 'string') {
    if (Array.isArray(parameters)) {
      return new ArrayBasedExecutor(client, query, parameters, options).execute();
    }

    if (parameters instanceof Stream) {
      return new StreamBasedExecutor(client, query, parameters, options).execute();
    }

    throw new TypeError('parameters should be an Array or a Stream instance');
  }

  if (Array.isArray(query)) {
    options = parameters;
    return new ArrayBasedExecutor(client, null, query, options).execute();
  }

  throw new TypeError('A string query or query and parameters array should be provided');
}
function executeConcurrent(client, query, parameters, options) {
  if (!client) {
    throw new TypeError('Client instance is not defined');
  }

  if (typeof query === 'string') {
    if (Array.isArray(parameters)) {
      return new ArrayBasedExecutor(client, query, parameters, options).execute();
    }

    if (parameters instanceof Stream) {
      return new StreamBasedExecutor(client, query, parameters, options).execute();
    }

    throw new TypeError('parameters should be an Array or a Stream instance');
  }

  if (Array.isArray(query)) {
    options = parameters;
    return new ArrayBasedExecutor(client, null, query, options).execute();
  }

  throw new TypeError('A string query or query and parameters array should be provided');
}
Utilities for concurrent query execution with the DataStax Node.js Driver.
@module concurrent
 
Executes multiple queries concurrently at the defined concurrency level.
@static
@param {Client} client The {@link Client} instance.
@param {String|Array<{query, params}>} query The query to execute per each parameter item.
@param {Array<Array>|Stream|Object} parameters An {@link Array} or a readable {@link Stream} composed of {@link Array}
items representing each individual set of parameters. Per each item in the {@link Array} or {@link Stream}, an
execution is going to be made.
@param {Object} [options] The execution options.
@param {String} [options.executionProfile] The execution profile to be used.
@param {Number} [options.concurrencyLevel=100] The concurrency level to determine the maximum amount of in-flight
operations at any given time
@param {Boolean} [options.raiseOnFirstError=true] Determines whether execution should stop after the first failed
execution and the corresponding exception will be raised.
@param {Boolean} [options.collectResults=false] Determines whether each individual
[ResultSet]{@link module:types~ResultSet} instance should be collected in the grouped result.
@param {Number} [options.maxErrors=100] The maximum amount of errors to be collected before ignoring the rest of
the error results.
@returns {Promise<ResultSetGroup>} A <code>Promise</code> of {@link ResultSetGroup} that is resolved when all the
executions completed and it's rejected when <code>raiseOnFirstError</code> is <code>true</code> and there is one
or more failures.
@example <caption>Using a fixed query and an Array of Arrays as parameters</caption>
const query = 'INSERT INTO table1 (id, value) VALUES (?, ?)';
const parameters = [[1, 'a'], [2, 'b'], [3, 'c'], ]; // ...
const result = await executeConcurrent(client, query, parameters);
@example <caption>Using a fixed query and a readable stream</caption>
const stream = csvStream.pipe(transformLineToArrayStream);
const result = await executeConcurrent(client, query, stream);
@example <caption>Using a different queries</caption>
const queryAndParameters = [
{ query: 'INSERT INTO videos (id, name, user_id) VALUES (?, ?, ?)',
params: [ id, name, userId ] },
{ query: 'INSERT INTO user_videos (user_id, id, name) VALUES (?, ?, ?)',
params: [ userId, id, name ] },
{ query: 'INSERT INTO latest_videos (id, name, user_id) VALUES (?, ?, ?)',
params: [ id, name, userId ] },
];

const result = await executeConcurrent(client, queryAndParameters);