\begin{quote}
Run multiple promise-\/returning \& async functions with limited concurrency \end{quote}
\hypertarget{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6682}{}\doxysection{Install}\label{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6682}

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

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

\begin{DoxyCode}{0}
\DoxyCodeLine{const pLimit = require('p-\/limit');}
\DoxyCodeLine{}
\DoxyCodeLine{const limit = pLimit(1);}
\DoxyCodeLine{}
\DoxyCodeLine{const input = [}
\DoxyCodeLine{    limit(() => fetchSomething('foo')),}
\DoxyCodeLine{    limit(() => fetchSomething('bar')),}
\DoxyCodeLine{    limit(() => doSomething())}
\DoxyCodeLine{];}
\DoxyCodeLine{}
\DoxyCodeLine{(async () => \{}
\DoxyCodeLine{    // Only one promise is run at once}
\DoxyCodeLine{    const result = await Promise.all(input);}
\DoxyCodeLine{    console.log(result);}
\DoxyCodeLine{\})(); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6684}{}\doxysection{API}\label{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6684}
\hypertarget{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6685}{}\doxysubsection{p\+Limit(concurrency)}\label{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6685}
Returns a {\ttfamily limit} function.\hypertarget{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6686}{}\doxysubsubsection{concurrency}\label{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6686}
Type\+: {\ttfamily number}\textbackslash{} Minimum\+: {\ttfamily 1}\textbackslash{} Default\+: {\ttfamily Infinity}

Concurrency limit.\hypertarget{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6687}{}\doxysubsection{limit(fn, ...\+args)}\label{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6687}
Returns the promise returned by calling {\ttfamily fn(...\+args)}.\hypertarget{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6688}{}\doxysubsubsection{fn}\label{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6688}
Type\+: {\ttfamily Function}

Promise-\/returning/async function.\hypertarget{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6689}{}\doxysubsubsection{args}\label{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6689}
Any arguments to pass through to {\ttfamily fn}.

Support for passing arguments on to the {\ttfamily fn} is provided in order to be able to avoid creating unnecessary closures. You probably don\textquotesingle{}t need this optimization unless you\textquotesingle{}re pushing a {\itshape lot} of functions.\hypertarget{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6690}{}\doxysubsection{limit.\+active\+Count}\label{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6690}
The number of promises that are currently running.\hypertarget{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6691}{}\doxysubsection{limit.\+pending\+Count}\label{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6691}
The number of promises that are waiting to run (i.\+e. their internal {\ttfamily fn} was not called yet).\hypertarget{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6692}{}\doxysubsection{limit.\+clear\+Queue()}\label{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6692}
Discard pending promises that are waiting to run.

This might be useful if you want to teardown the queue at the end of your program\textquotesingle{}s lifecycle or discard any function calls referencing an intermediary state of your app.

Note\+: This does not cancel promises that are already running.\hypertarget{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6693}{}\doxysection{FAQ}\label{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6693}
\hypertarget{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6694}{}\doxysubsection{How is this different from the $<$a href=\char`\"{}https\+://github.\+com/sindresorhus/p-\/queue\char`\"{}$>$$<$tt$>$p-\/queue$<$/tt$>$$<$/a$>$ package?}\label{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6694}
This package is only about limiting the number of concurrent executions, while {\ttfamily p-\/queue} is a fully featured queue implementation with lots of different options, introspection, and ability to pause the queue.\hypertarget{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6695}{}\doxysection{Related}\label{md_sfcode_node_modules_copy_webpack_plugin_node_modules_p_limit_readme_autotoc_md6695}

\begin{DoxyItemize}
\item \href{https://github.com/sindresorhus/p-queue}{\texttt{ p-\/queue}} -\/ Promise queue with concurrency control
\item \href{https://github.com/sindresorhus/p-throttle}{\texttt{ p-\/throttle}} -\/ Throttle promise-\/returning \& async functions
\item \href{https://github.com/sindresorhus/p-debounce}{\texttt{ p-\/debounce}} -\/ Debounce promise-\/returning \& async functions
\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/promise-fun}{\texttt{ More…}}
\end{DoxyItemize}

\DoxyHorRuler{0}


 {\bfseries{ \href{https://tidelift.com/subscription/pkg/npm-p-limit?utm_source=npm-p-limit&utm_medium=referral&utm_campaign=readme}{\texttt{ Get professional support for this package with a Tidelift subscription}} }} ~\newline
 \textsubscript{ Tidelift helps make open source sustainable for maintainers while giving companies~\newline
assurances about security, maintenance, and licensing for their dependencies. }  