\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_find_cache_dir_node_modules_p_locate_readme_autotoc_md10714}{}\doxysection{Install}\label{md_sfcode_node_modules_find_cache_dir_node_modules_p_locate_readme_autotoc_md10714}

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

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_find_cache_dir_node_modules_p_locate_readme_autotoc_md10715}{}\doxysection{Usage}\label{md_sfcode_node_modules_find_cache_dir_node_modules_p_locate_readme_autotoc_md10715}
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_find_cache_dir_node_modules_p_locate_readme_autotoc_md10716}{}\doxysection{API}\label{md_sfcode_node_modules_find_cache_dir_node_modules_p_locate_readme_autotoc_md10716}
\hypertarget{md_sfcode_node_modules_find_cache_dir_node_modules_p_locate_readme_autotoc_md10717}{}\doxysubsection{p\+Locate(input, tester, \mbox{[}options\mbox{]})}\label{md_sfcode_node_modules_find_cache_dir_node_modules_p_locate_readme_autotoc_md10717}
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_find_cache_dir_node_modules_p_locate_readme_autotoc_md10718}{}\doxysubsubsection{input}\label{md_sfcode_node_modules_find_cache_dir_node_modules_p_locate_readme_autotoc_md10718}
Type\+: {\ttfamily Iterable$<$Promise $\vert$ unknown$>$}

An iterable of promises/values to test.\hypertarget{md_sfcode_node_modules_find_cache_dir_node_modules_p_locate_readme_autotoc_md10719}{}\doxysubsubsection{tester(element)}\label{md_sfcode_node_modules_find_cache_dir_node_modules_p_locate_readme_autotoc_md10719}
Type\+: {\ttfamily Function}

This function will receive resolved values from {\ttfamily input} and is expected to return a {\ttfamily Promise$<$boolean$>$} or {\ttfamily boolean}.\hypertarget{md_sfcode_node_modules_find_cache_dir_node_modules_p_locate_readme_autotoc_md10720}{}\doxysubsubsection{options}\label{md_sfcode_node_modules_find_cache_dir_node_modules_p_locate_readme_autotoc_md10720}
Type\+: {\ttfamily Object}\hypertarget{md_sfcode_node_modules_find_cache_dir_node_modules_p_locate_readme_autotoc_md10721}{}\doxyparagraph{concurrency}\label{md_sfcode_node_modules_find_cache_dir_node_modules_p_locate_readme_autotoc_md10721}
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_find_cache_dir_node_modules_p_locate_readme_autotoc_md10722}{}\doxyparagraph{preserve\+Order}\label{md_sfcode_node_modules_find_cache_dir_node_modules_p_locate_readme_autotoc_md10722}
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_find_cache_dir_node_modules_p_locate_readme_autotoc_md10723}{}\doxysection{Related}\label{md_sfcode_node_modules_find_cache_dir_node_modules_p_locate_readme_autotoc_md10723}

\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_find_cache_dir_node_modules_p_locate_readme_autotoc_md10724}{}\doxysection{License}\label{md_sfcode_node_modules_find_cache_dir_node_modules_p_locate_readme_autotoc_md10724}
MIT © \href{https://sindresorhus.com}{\texttt{ Sindre Sorhus}} 