.. _cartridge.pool:

===============================================================================
Module *cartridge.pool*
===============================================================================

Connection pool.



Reuse tarantool net.box connections with ease.


-------------------------------------------------------------------------------
Functions
-------------------------------------------------------------------------------


.. _cartridge.pool.connect:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
connect (uri[, opts])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Connect a remote or get cached connection. 
Connection is established using  ``net.box.connect()`` .


**Parameters:**

- *uri:* (`string <https://www.lua.org/manual/5.1/manual.html#5.4>`_)   
- *opts:* 

  - *wait_connected:* (**boolean** or **number**) by default, connection creation is blocked until theconnection is established, but passing  ``wait_connected=false`` makes it return immediately. Also, passing a timeout makes itwait before returning (e.g.  ``wait_connected=1.5``  makes it waitat most 1.5 seconds).  
  - *connect_timeout:* (optional **number**) (*deprecated*)Use `wait_connected` instead  
  - *user:*  (*deprecated*) don't use it  
  - *password:*  (*deprecated*) don't use it  
  - *reconnect_after:*  (*deprecated*) don't use it  


**Returns**:

``net.box``  connection


**Or**

(**nil**) 

(`table <https://www.lua.org/manual/5.1/manual.html#5.5>`_) Error description


-------------------------------------------------------------------------------
Local Functions
-------------------------------------------------------------------------------


.. _cartridge.pool.format_uri:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
format_uri (uri)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Enrich URI with credentials. 
Suitable to connect other cluster instances.



**Parameters:**

- *uri:* (`string <https://www.lua.org/manual/5.1/manual.html#5.4>`_) `host:port`  

**Returns**:

(`string <https://www.lua.org/manual/5.1/manual.html#5.4>`_) `username:password@host:port`


.. _cartridge.pool.map_call:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
map_call (fn_name[, args[, opts]])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Perform a remote call to multiple URIs and map results. 

(**Added** in v1.2.0-17)


**Parameters:**

- *fn_name:* (`string <https://www.lua.org/manual/5.1/manual.html#5.4>`_)   
- *args:* (`table <https://www.lua.org/manual/5.1/manual.html#5.5>`_) function arguments (optional) 
- *opts:* 

  - *uri_list:* (`{string,...} <https://www.lua.org/manual/5.1/manual.html#5.4>`_) array of URIs for performing remote call  
  - *timeout:* (optional **number**) passed to  ``net.box``   ``conn:call()``   


**Returns**:

(**{URI=value,...}**) Call results mapping for every URI.

(`table <https://www.lua.org/manual/5.1/manual.html#5.5>`_) United error object, gathering errors for every URI that failed.


