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

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

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

\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_p_limit_readme_autotoc_md19282}{}\doxysection{API}\label{md_sfcode_node_modules_p_limit_readme_autotoc_md19282}
\hypertarget{md_sfcode_node_modules_p_limit_readme_autotoc_md19283}{}\doxysubsection{p\+Limit(concurrency)}\label{md_sfcode_node_modules_p_limit_readme_autotoc_md19283}
Returns a {\ttfamily limit} function.\hypertarget{md_sfcode_node_modules_p_limit_readme_autotoc_md19284}{}\doxysubsubsection{concurrency}\label{md_sfcode_node_modules_p_limit_readme_autotoc_md19284}
Type\+: {\ttfamily number}\textbackslash{} Minimum\+: {\ttfamily 1}\textbackslash{} Default\+: {\ttfamily Infinity}

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

Promise-\/returning/async function.\hypertarget{md_sfcode_node_modules_p_limit_readme_autotoc_md19287}{}\doxysubsubsection{args}\label{md_sfcode_node_modules_p_limit_readme_autotoc_md19287}
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_p_limit_readme_autotoc_md19288}{}\doxysubsection{limit.\+active\+Count}\label{md_sfcode_node_modules_p_limit_readme_autotoc_md19288}
The number of promises that are currently running.\hypertarget{md_sfcode_node_modules_p_limit_readme_autotoc_md19289}{}\doxysubsection{limit.\+pending\+Count}\label{md_sfcode_node_modules_p_limit_readme_autotoc_md19289}
The number of promises that are waiting to run (i.\+e. their internal {\ttfamily fn} was not called yet).\hypertarget{md_sfcode_node_modules_p_limit_readme_autotoc_md19290}{}\doxysubsection{limit.\+clear\+Queue()}\label{md_sfcode_node_modules_p_limit_readme_autotoc_md19290}
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_p_limit_readme_autotoc_md19291}{}\doxysection{FAQ}\label{md_sfcode_node_modules_p_limit_readme_autotoc_md19291}
\hypertarget{md_sfcode_node_modules_p_limit_readme_autotoc_md19292}{}\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_p_limit_readme_autotoc_md19292}
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_p_limit_readme_autotoc_md19293}{}\doxysection{Related}\label{md_sfcode_node_modules_p_limit_readme_autotoc_md19293}

\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. }  