Simple email application for Android. Original source code: https://framagit.org/dystopia-project/simple-email
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.0 KiB

  1. # p-locate [![Build Status](https://travis-ci.org/sindresorhus/p-locate.svg?branch=master)](https://travis-ci.org/sindresorhus/p-locate)
  2. > Get the first fulfilled promise that satisfies the provided testing function
  3. Think of it like an async version of [`Array#find`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/find).
  4. ## Install
  5. ```
  6. $ npm install --save p-locate
  7. ```
  8. ## Usage
  9. Here we find the first file that exists on disk, in array order.
  10. ```js
  11. const pathExists = require('path-exists');
  12. const pLocate = require('p-locate');
  13. const files = [
  14. 'unicorn.png',
  15. 'rainbow.png', // only this one actually exists on disk
  16. 'pony.png'
  17. ];
  18. pLocate(files, file => pathExists(file)).then(foundPath => {
  19. console.log(foundPath);
  20. //=> 'rainbow'
  21. });
  22. ```
  23. *The above is just an example. Use [`locate-path`](https://github.com/sindresorhus/locate-path) if you need this.*
  24. ## API
  25. ### pLocate(input, tester, [options])
  26. Returns a `Promise` that is fulfilled when `tester` resolves to `true` or the iterable is done, or rejects if any of the promises reject. The fulfilled value is the current iterable value or `undefined` if `tester` never resolved to `true`.
  27. #### input
  28. Type: `Iterable<Promise|any>`
  29. #### tester(element)
  30. Type: `Function`
  31. Expected to return a `Promise<boolean>` or boolean.
  32. #### options
  33. Type: `Object`
  34. ##### concurrency
  35. Type: `number`<br>
  36. Default: `Infinity`<br>
  37. Minimum: `1`
  38. Number of concurrently pending promises returned by `tester`.
  39. ##### preserveOrder
  40. Type: `boolean`<br>
  41. Default: `true`
  42. Preserve `input` order when searching.
  43. Disable this to improve performance if you don't care about the order.
  44. ## Related
  45. - [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently
  46. - [p-filter](https://github.com/sindresorhus/p-filter) - Filter promises concurrently
  47. - [p-any](https://github.com/sindresorhus/p-any) - Wait for any promise to be fulfilled
  48. - [More…](https://github.com/sindresorhus/promise-fun)
  49. ## License
  50. MIT © [Sindre Sorhus](https://sindresorhus.com)