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.

81 lines
2.1 KiB

  1. # p-map [![Build Status](https://travis-ci.org/sindresorhus/p-map.svg?branch=master)](https://travis-ci.org/sindresorhus/p-map)
  2. > Map over promises concurrently
  3. Useful when you need to run promise-returning & async functions multiple times with different inputs concurrently.
  4. ## Install
  5. ```
  6. $ npm install p-map
  7. ```
  8. ## Usage
  9. ```js
  10. const pMap = require('p-map');
  11. const got = require('got');
  12. const sites = [
  13. getWebsiteFromUsername('sindresorhus'), //=> Promise
  14. 'ava.li',
  15. 'todomvc.com',
  16. 'github.com'
  17. ];
  18. const mapper = el => got.head(el).then(res => res.requestUrl);
  19. pMap(sites, mapper, {concurrency: 2}).then(result => {
  20. console.log(result);
  21. //=> ['http://sindresorhus.com/', 'http://ava.li/', 'http://todomvc.com/', 'http://github.com/']
  22. });
  23. ```
  24. ## API
  25. ### pMap(input, mapper, [options])
  26. Returns a `Promise` that is fulfilled when all promises in `input` and ones returned from `mapper` are fulfilled, or rejects if any of the promises reject. The fulfilled value is an `Array` of the fulfilled values returned from `mapper` in `input` order.
  27. #### input
  28. Type: `Iterable<Promise|any>`
  29. Iterated over concurrently in the `mapper` function.
  30. #### mapper(element, index)
  31. Type: `Function`
  32. Expected to return a `Promise` or value.
  33. #### options
  34. Type: `Object`
  35. ##### concurrency
  36. Type: `number`<br>
  37. Default: `Infinity`<br>
  38. Minimum: `1`
  39. Number of concurrently pending promises returned by `mapper`.
  40. ## Related
  41. - [p-all](https://github.com/sindresorhus/p-all) - Run promise-returning & async functions concurrently with optional limited concurrency
  42. - [p-filter](https://github.com/sindresorhus/p-filter) - Filter promises concurrently
  43. - [p-times](https://github.com/sindresorhus/p-times) - Run promise-returning & async functions a specific number of times concurrently
  44. - [p-props](https://github.com/sindresorhus/p-props) - Like `Promise.all()` but for `Map` and `Object`
  45. - [p-map-series](https://github.com/sindresorhus/p-map-series) - Map over promises serially
  46. - [p-queue](https://github.com/sindresorhus/p-queue) - Promise queue with concurrency control
  47. - [More…](https://github.com/sindresorhus/promise-fun)
  48. ## License
  49. MIT © [Sindre Sorhus](https://sindresorhus.com)