# concurrent

<div class="jsdoc-content"><header>
    
        
            
        
    
</header>


    
        
            <div class="description"><p>Utilities for concurrent query execution with the DataStax Node.js Driver.</p></div>
        

        
            















<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/concurrent/index.js#L8" target="_blank" rel="noopener">concurrent/index.js, line 8</a></p></div>




















        
    
    

    

    

    

    

    

    

    

    
        </div>

## Methods

<div class="jsdoc-content">

        
            

    

    
    <h3 class="name" id=".executeConcurrent"><span class="type-signature">(static) </span>executeConcurrent<span class="signature">(client, query, parameters, options<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise&lt;ResultSetGroup>}</span></h3>
    

    



<div class="description">
    <p>Executes multiple queries concurrently at the defined concurrency level.</p>
</div>









    <h4>Parameters:</h4>
    

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        
        <th>Attributes</th>
        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>client</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="../Client.html">Client</a></span>


            
            </td>

            
                <td class="attributes">
                

                

                
                </td>
            

            

            <td class="description last"><p>The <a href="../Client.html">Client</a> instance.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>query</code></td>
            

            <td class="type">
            
                
<span class="param-type">String</span>
|

<span class="param-type">Array&lt;{query, params}></span>


            
            </td>

            
                <td class="attributes">
                

                

                
                </td>
            

            

            <td class="description last"><p>The query to execute per each parameter item.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>parameters</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array&lt;Array&lt;any>></span>
|

<span class="param-type">Stream</span>
|

<span class="param-type">Object</span>


            
            </td>

            
                <td class="attributes">
                

                

                
                </td>
            

            

            <td class="description last"><p>An Array or a readable Stream composed of Array
items representing each individual set of parameters. Per each item in the Array or Stream, an
execution is going to be made.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>options</code></td>
            

            <td class="type">
            
                
<span class="param-type">Object</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            

            <td class="description last"><p>The execution options.</p>
                <h5>Properties</h5>
                

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        
        <th>Attributes</th>
        

        
        <th>Default</th>
        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>executionProfile</code></td>
            

            <td class="type">
            
                
<span class="param-type">String</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            
                <td class="default">
                
                </td>
            

            <td class="description last"><p>The execution profile to be used.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>concurrencyLevel</code></td>
            

            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            
                <td class="default">
                
                    100
                
                </td>
            

            <td class="description last"><p>The concurrency level to determine the maximum amount of in-flight
operations at any given time</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>raiseOnFirstError</code></td>
            

            <td class="type">
            
                
<span class="param-type">Boolean</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            
                <td class="default">
                
                    true
                
                </td>
            

            <td class="description last"><p>Determines whether execution should stop after the first failed
execution and the corresponding exception will be raised.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>collectResults</code></td>
            

            <td class="type">
            
                
<span class="param-type">Boolean</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            
                <td class="default">
                
                    false
                
                </td>
            

            <td class="description last"><p>Determines whether each individual
<a href="../types/ResultSet.html">ResultSet</a> instance should be collected in the grouped result.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>maxErrors</code></td>
            

            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            
                <td class="default">
                
                    100
                
                </td>
            

            <td class="description last"><p>The maximum amount of errors to be collected before ignoring the rest of
the error results.</p></td>
        </tr>

    
    </tbody>
</table>

            </td>
        </tr>

    
    </tbody>
</table>






<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/concurrent/index.js#L53" target="_blank" rel="noopener">concurrent/index.js, line 53</a></p></div>















<h4>Returns:</h4>

        
<div class="param-desc">
    <p>A <code>Promise</code> of 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.</p>
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise&lt;ResultSetGroup></span>


    </dd>
</dl>

    




    <h4>Examples</h4>
    
        <p class="code-caption">Using a fixed query and an Array of Arrays as parameters</p>
    
    <div class="highlight-javascript notranslate"><div class="highlight"><pre>const query = 'INSERT INTO table1 (id, value) VALUES (?, ?)';
const parameters = [[1, 'a'], [2, 'b'], [3, 'c'], ]; // ...
const result = await executeConcurrent(client, query, parameters);</pre></div></div>

        <p class="code-caption">Using a fixed query and a readable stream</p>
    
    <div class="highlight-javascript notranslate"><div class="highlight"><pre>const stream = csvStream.pipe(transformLineToArrayStream);
const result = await executeConcurrent(client, query, stream);</pre></div></div>

        <p class="code-caption">Using a different queries</p>
    
    <div class="highlight-javascript notranslate"><div class="highlight"><pre>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);</pre></div></div></div>
