\begin{quote}
Map over promises concurrently \end{quote}
Useful when you need to run promise-\/returning \& async functions multiple times with different inputs concurrently.\hypertarget{md_sfcode_node_modules_p_map_readme_autotoc_md19308}{}\doxysection{Install}\label{md_sfcode_node_modules_p_map_readme_autotoc_md19308}

\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install p-\/map }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_p_map_readme_autotoc_md19309}{}\doxysection{Usage}\label{md_sfcode_node_modules_p_map_readme_autotoc_md19309}

\begin{DoxyCode}{0}
\DoxyCodeLine{const pMap = require('p-\/map');}
\DoxyCodeLine{const got = require('got');}
\DoxyCodeLine{}
\DoxyCodeLine{const sites = [}
\DoxyCodeLine{    getWebsiteFromUsername('https://sindresorhus'), //=> Promise}
\DoxyCodeLine{    'https://ava.li',}
\DoxyCodeLine{    'https://github.com'}
\DoxyCodeLine{];}
\DoxyCodeLine{}
\DoxyCodeLine{(async () => \{}
\DoxyCodeLine{    const mapper = async site => \{}
\DoxyCodeLine{        const \{requestUrl\} = await got.head(site);}
\DoxyCodeLine{        return requestUrl;}
\DoxyCodeLine{    \};}
\DoxyCodeLine{}
\DoxyCodeLine{    const result = await pMap(sites, mapper, \{concurrency: 2\});}
\DoxyCodeLine{}
\DoxyCodeLine{    console.log(result);}
\DoxyCodeLine{    //=> ['https://sindresorhus.com/', 'https://ava.li/', 'https://github.com/']}
\DoxyCodeLine{\})(); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_p_map_readme_autotoc_md19310}{}\doxysection{API}\label{md_sfcode_node_modules_p_map_readme_autotoc_md19310}
\hypertarget{md_sfcode_node_modules_p_map_readme_autotoc_md19311}{}\doxysubsection{p\+Map(input, mapper, options?)}\label{md_sfcode_node_modules_p_map_readme_autotoc_md19311}
Returns a {\ttfamily Promise} that is fulfilled when all promises in {\ttfamily input} and ones returned from {\ttfamily mapper} are fulfilled, or rejects if any of the promises reject. The fulfilled value is an {\ttfamily Array} of the fulfilled values returned from {\ttfamily mapper} in {\ttfamily input} order.\hypertarget{md_sfcode_node_modules_p_map_readme_autotoc_md19312}{}\doxysubsubsection{input}\label{md_sfcode_node_modules_p_map_readme_autotoc_md19312}
Type\+: {\ttfamily Iterable$<$Promise $\vert$ unknown$>$}

Iterated over concurrently in the {\ttfamily mapper} function.\hypertarget{md_sfcode_node_modules_p_map_readme_autotoc_md19313}{}\doxysubsubsection{mapper(element, index)}\label{md_sfcode_node_modules_p_map_readme_autotoc_md19313}
Type\+: {\ttfamily Function}

Expected to return a {\ttfamily Promise} or value.\hypertarget{md_sfcode_node_modules_p_map_readme_autotoc_md19314}{}\doxysubsubsection{options}\label{md_sfcode_node_modules_p_map_readme_autotoc_md19314}
Type\+: {\ttfamily object}\hypertarget{md_sfcode_node_modules_p_map_readme_autotoc_md19315}{}\doxyparagraph{concurrency}\label{md_sfcode_node_modules_p_map_readme_autotoc_md19315}
Type\+: {\ttfamily number} (Integer)\textbackslash{} Default\+: {\ttfamily Infinity}\textbackslash{} Minimum\+: {\ttfamily 1}

Number of concurrently pending promises returned by {\ttfamily mapper}.\hypertarget{md_sfcode_node_modules_p_map_readme_autotoc_md19316}{}\doxyparagraph{stop\+On\+Error}\label{md_sfcode_node_modules_p_map_readme_autotoc_md19316}
Type\+: {\ttfamily boolean}\textbackslash{} Default\+: {\ttfamily true}

When set to {\ttfamily false}, instead of stopping when a promise rejects, it will wait for all the promises to settle and then reject with an \href{https://github.com/sindresorhus/aggregate-error}{\texttt{ aggregated error}} containing all the errors from the rejected promises.\hypertarget{md_sfcode_node_modules_p_map_readme_autotoc_md19317}{}\doxysection{p-\/map for enterprise}\label{md_sfcode_node_modules_p_map_readme_autotoc_md19317}
Available as part of the Tidelift Subscription.

The maintainers of p-\/map and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. \href{https://tidelift.com/subscription/pkg/npm-p-map?utm_source=npm-p-map&utm_medium=referral&utm_campaign=enterprise&utm_term=repo}{\texttt{ Learn more.}}\hypertarget{md_sfcode_node_modules_p_map_readme_autotoc_md19318}{}\doxysection{Related}\label{md_sfcode_node_modules_p_map_readme_autotoc_md19318}

\begin{DoxyItemize}
\item \href{https://github.com/sindresorhus/p-all}{\texttt{ p-\/all}} -\/ Run promise-\/returning \& async functions concurrently with optional limited concurrency
\item \href{https://github.com/sindresorhus/p-filter}{\texttt{ p-\/filter}} -\/ Filter promises concurrently
\item \href{https://github.com/sindresorhus/p-times}{\texttt{ p-\/times}} -\/ Run promise-\/returning \& async functions a specific number of times concurrently
\item \href{https://github.com/sindresorhus/p-props}{\texttt{ p-\/props}} -\/ Like {\ttfamily Promise.\+all()} but for {\ttfamily Map} and {\ttfamily Object}
\item \href{https://github.com/sindresorhus/p-map-series}{\texttt{ p-\/map-\/series}} -\/ Map over promises serially
\item \href{https://github.com/sindresorhus/p-queue}{\texttt{ p-\/queue}} -\/ Promise queue with concurrency control
\item \href{https://github.com/sindresorhus/promise-fun}{\texttt{ More…}} 
\end{DoxyItemize}