\begin{quote}
Get the first fulfilled promise that satisfies the provided testing function \end{quote}
Think of it like an async version of \href{https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/find}{\texttt{ {\ttfamily Array\#find}}}.\hypertarget{md_sfcode_node_modules_p_locate_readme_autotoc_md19296}{}\doxysection{Install}\label{md_sfcode_node_modules_p_locate_readme_autotoc_md19296}

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

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_p_locate_readme_autotoc_md19297}{}\doxysection{Usage}\label{md_sfcode_node_modules_p_locate_readme_autotoc_md19297}
Here we find the first file that exists on disk, in array order.


\begin{DoxyCode}{0}
\DoxyCodeLine{const pathExists = require('path-\/exists');}
\DoxyCodeLine{const pLocate = require('p-\/locate');}
\DoxyCodeLine{}
\DoxyCodeLine{const files = [}
\DoxyCodeLine{    'unicorn.png',}
\DoxyCodeLine{    'rainbow.png', // Only this one actually exists on disk}
\DoxyCodeLine{    'pony.png'}
\DoxyCodeLine{];}
\DoxyCodeLine{}
\DoxyCodeLine{(async () => \{}
\DoxyCodeLine{    const foundPath = await pLocate(files, file => pathExists(file));}
\DoxyCodeLine{}
\DoxyCodeLine{    console.log(foundPath);}
\DoxyCodeLine{    //=> 'rainbow'}
\DoxyCodeLine{\})(); }

\end{DoxyCode}


$\ast$\+The above is just an example. Use \href{https://github.com/sindresorhus/locate-path}{\texttt{ {\ttfamily locate-\/path}}} if you need this.$\ast$\hypertarget{md_sfcode_node_modules_p_locate_readme_autotoc_md19298}{}\doxysection{API}\label{md_sfcode_node_modules_p_locate_readme_autotoc_md19298}
\hypertarget{md_sfcode_node_modules_p_locate_readme_autotoc_md19299}{}\doxysubsection{p\+Locate(input, tester, \mbox{[}options\mbox{]})}\label{md_sfcode_node_modules_p_locate_readme_autotoc_md19299}
Returns a {\ttfamily Promise} that is fulfilled when {\ttfamily tester} resolves to {\ttfamily true} or the iterable is done, or rejects if any of the promises reject. The fulfilled value is the current iterable value or {\ttfamily undefined} if {\ttfamily tester} never resolved to {\ttfamily true}.\hypertarget{md_sfcode_node_modules_p_locate_readme_autotoc_md19300}{}\doxysubsubsection{input}\label{md_sfcode_node_modules_p_locate_readme_autotoc_md19300}
Type\+: {\ttfamily Iterable$<$Promise$\vert$any$>$}\hypertarget{md_sfcode_node_modules_p_locate_readme_autotoc_md19301}{}\doxysubsubsection{tester(element)}\label{md_sfcode_node_modules_p_locate_readme_autotoc_md19301}
Type\+: {\ttfamily Function}

Expected to return a {\ttfamily Promise$<$boolean$>$} or boolean.\hypertarget{md_sfcode_node_modules_p_locate_readme_autotoc_md19302}{}\doxysubsubsection{options}\label{md_sfcode_node_modules_p_locate_readme_autotoc_md19302}
Type\+: {\ttfamily Object}\hypertarget{md_sfcode_node_modules_p_locate_readme_autotoc_md19303}{}\doxyparagraph{concurrency}\label{md_sfcode_node_modules_p_locate_readme_autotoc_md19303}
Type\+: {\ttfamily number}~\newline
 Default\+: {\ttfamily Infinity}~\newline
 Minimum\+: {\ttfamily 1}

Number of concurrently pending promises returned by {\ttfamily tester}.\hypertarget{md_sfcode_node_modules_p_locate_readme_autotoc_md19304}{}\doxyparagraph{preserve\+Order}\label{md_sfcode_node_modules_p_locate_readme_autotoc_md19304}
Type\+: {\ttfamily boolean}~\newline
 Default\+: {\ttfamily true}

Preserve {\ttfamily input} order when searching.

Disable this to improve performance if you don\textquotesingle{}t care about the order.\hypertarget{md_sfcode_node_modules_p_locate_readme_autotoc_md19305}{}\doxysection{Related}\label{md_sfcode_node_modules_p_locate_readme_autotoc_md19305}

\begin{DoxyItemize}
\item \href{https://github.com/sindresorhus/p-map}{\texttt{ p-\/map}} -\/ Map over promises concurrently
\item \href{https://github.com/sindresorhus/p-filter}{\texttt{ p-\/filter}} -\/ Filter promises concurrently
\item \href{https://github.com/sindresorhus/p-any}{\texttt{ p-\/any}} -\/ Wait for any promise to be fulfilled
\item \href{https://github.com/sindresorhus/promise-fun}{\texttt{ More…}}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_p_locate_readme_autotoc_md19306}{}\doxysection{License}\label{md_sfcode_node_modules_p_locate_readme_autotoc_md19306}
MIT © \href{https://sindresorhus.com}{\texttt{ Sindre Sorhus}} 