3.0.0 • Published 4 years ago

p-map-series v3.0.0

Weekly downloads
1,932,818
License
MIT
Repository
github
Last release
4 years ago

p-map-series

Map over promises serially

Useful as a side-effect mapper. Use p-map if you don't need side-effects, as it's concurrent.

Install

$ npm install p-map-series

Usage

import pMapSeries from 'p-map-series';

const keywords = [
	getTopKeyword() //=> Promise
	'rainbow',
	'pony'
];

let scores = [];

const mapper = async keyword => {
	const score = await fetchScore(keyword);
	scores.push(score);
	return {keyword, score};
});

console.log(await pMapSeries(keywords, mapper));
/*
[
	{
		keyword: 'unicorn',
		score: 99
	},
	{
		keyword: 'rainbow',
		score: 70
	},
	{
		keyword: 'pony',
		score: 79
	}
]
*/

API

pMapSeries(input, mapper)

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 mapper created promises fulfillment values.

input

Type: Iterable<Promise | unknown>

Mapped over serially in the mapper function.

mapper(element, index)

Type: Function

Expected to return a value. If it's a Promise, it's awaited before continuing with the next iteration.

Related

  • p-each-series - Iterate over promises serially
  • p-reduce - Reduce a list of values using promises into a promise for a value
  • p-map - Map over promises concurrently
  • More…

lerna@lerna/create@lerna/symlink-dependenciesbin-build@megasaur/run-parallel-batches@megasaur/symlink-dependencies@megasaur/bootstrap@megasaur/clean@megasaur/importbit-bin@applitools/cdt-page-renderer@code-uprising/handler-schema-inspector@cold-start/handler-schema-inspector@frxf/frxfcogoportutilsunblock-block-save-variables@everything-registry/sub-chunk-2396fixed_form_builderfunctional-validatorg-applyjammery-clijamuskaliml2forlernaiiif-manifest-editormisciblenextionnode-app-hivep-thunkp-funp-suitep-promise-utilsnvxorbit-db-access-controllersorbit-db-cliorbitdnsjeuxuiluojia-cli-devmandarin@hume/utils@infinitebrahmanuniverse/nolb-p-@lerna/legacy-package-management@lerna/run-parallel-batches@localnerve/bin-build@merna/symlink-dependencies@merna/bootstrap@merna/clean@merna/import@mcesystems/lerna@deep-grasp/build@hieuquang2212/form@jesstelford/scriptsebit-bincandlelabssdk@teambit/pkg@teambit/update-dependencies@teambit/mocha@teambit/multi-tester@teambit/merging@teambit/scope@teambit/schema@teambit/renaming@teambit/removeethscriptions-indexerpyreswap-sdkpuddlenutspromise-funsushi-sdk-ftmrefinejs-repotdsmsciadvfilesspeedracerspydsindresorhus.js@buganto/client@chrisdothtml/monorepo-import@cactus-technologies/utils@billogram/janitorwinx-form-winx@abhinavoneuipoc/stencil-test@0x-lerna-fork/import@0x-lerna-fork/bootstrap@0x-lerna-fork/clean@0x-lerna-fork/run-parallel-batches@0x-lerna-fork/symlink-dependencieszzzxxxyyy321123@arco-cli/aspect@arco-cli/legacy@arco-cli/servicevideo-hashtitanouxpin-merge-tswebpack-hooks-shellscriptsxinquirer@erquhart/lerna-bootstrap@erquhart/lerna-clean@erquhart/lerna-import@erquhart/lerna-run-parallel-batches@erquhart/lerna-symlink-dependencies@teambit/merge-lanes@teambit/typescript
3.0.0

4 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.0.0

8 years ago