3.0.0 • Published 3 years ago

p-map-series v3.0.0

Weekly downloads
1,932,818
License
MIT
Repository
github
Last release
3 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/symlink-dependencies@lerna/createbin-buildlerna@megasaur/run-parallel-batches@megasaur/symlink-dependencies@megasaur/bootstrap@megasaur/clean@megasaur/importbit-bin@teambit/legacy@applitools/cdt-page-renderer@code-uprising/handler-schema-inspector@cold-start/handler-schema-inspector@frxf/frxfcogoportutilsunblock-block-save-variables@everything-registry/sub-chunk-2396webpack-hooks-shellscriptswinx-form-winxxinquirervideo-hashzzzxxxyyy321123refinejs-reposciadvfilestitanospeedracerspydsindresorhus.jstdsmsushi-sdk-ftmuxpin-merge-ts@lerna/run-parallel-batches@lerna/legacy-package-managementfb.me@localnerve/bin-buildebit-bin@hume/utils@infinitebrahmanuniverse/nolb-p-golgoth@nvon/node-toolbox@nvon/node-toolbox-cjs@merna/symlink-dependenciesfunctional-validator@merna/import@merna/bootstrap@merna/cleanfixed_form_builder@mcesystems/lernag-applygh-monoproject-cliethscriptions-indexer@jesstelford/scripts@revved/lib-common@safely-project/safely-ts@parallelnft/web3modal@react-18-pdf/root@positionex/position-sdk@hieuquang2212/form@pubbo/bootstrap@pubbo/clean@pubbo/import@pubbo/symlink-dependencies@erquhart/lerna-run-parallel-batches@erquhart/lerna-symlink-dependencies@erquhart/lerna-import@erquhart/lerna-bootstrap@erquhart/lerna-cleanjeuxuijammery-clijamuskalim@spryker-lerna/bootstrap@spryker-lerna/clean@spryker-lerna/symlink-dependencies@spryker-lerna/importl2forlerna@billogram/janitor@buganto/clientblobscriptionsblambda-cliawait-componentaskyaxe@teambit/component.testing.mock-components@teambit/dependencies@teambit/pkg@teambit/component-writer@teambit/multi-compiler@teambit/multi-tester@teambit/preview@teambit/prettier@teambit/dependency-resolver@teambit/eslint@teambit/envs@teambit/ui@teambit/typescript@teambit/update-dependencies@teambit/lanes@teambit/issues@teambit/workspace
3.0.0

3 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.0.0

8 years ago