3.0.0 • Published 4 years ago

p-each-series v3.0.0

Weekly downloads
10,189,039
License
MIT
Repository
github
Last release
4 years ago

p-each-series

Iterate over promises serially

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

Install

$ npm install p-each-series

Usage

import pEachSeries from 'p-each-series';

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

const iterator = async element => saveToDiskPromise(element);

console.log(await pEachSeries(keywords, iterator));
//=> ['unicorn', 'rainbow', 'pony']

API

pEachSeries(input, iterator)

Returns a Promise that is fulfilled when all promises in input and ones returned from iterator are fulfilled, or rejects if any of the promises reject. The fulfillment value is the original input.

input

Type: Iterable<Promise | unknown>

Iterated over serially in the iterator function.

iterator(element, index)

Type: Function

Return value is ignored unless it's Promise, then it's awaited before continuing with the next iteration.

pEachSeries.stop

Stop iterating through items by returning pEachSeries.stop from the iterator function.

import pEachSeries from 'p-each-series';

// Logs `a` and `b`.
const result = await pEachSeries(['a', 'b', 'c'], value => {
	console.log(value);

	if (value === 'b') {
		return pEachSeries.stop;
	}
});

console.log(result);
//=> ['a', 'b', 'c']

Related

  • p-map-series - Map over promises serially
  • p-series - Run promise-returning & async functions in series
  • p-pipe - Compose promise-returning & async functions into a reusable pipeline
  • p-waterfall - Run promise-returning & async functions in series, each passing its result to the next
  • p-reduce - Reduce a list of values using promises into a promise for a value
  • p-map - Map over promises concurrently
  • More…
react-native-bluetooth2killi8n-react-native-fast-imagereactifirecreate-geosecma-libraryspecify-importsbabel-specify-imports@icanpm/api-masterwebpack-cli-lernawebpack-cli-migratetypescriptifirereact-native-template-rfbase@dada513/discordio@cold-start/service-backups@cold-start/service-indexer@code-uprising/handler-schema-inspector@code-uprising/lambda-backups@code-uprising/rollup-plugin-html-template@cold-start/handler-schema-inspectorairscanairscan-examplereact-native-esc-pos-sahaab@borisovart/atol-kkt-module@bitexchange-ltd/bitexchange-server-7.5.0-beta.3deneme323112@robmayer/create-react-library@open-tech-world/create-node-lib@ntt_app/react-native-custom-notification@educationperfect/semantic-releasereact-native-covid-sdkgql_din_modbitgetreact-initializrreact-native-printer-brothersdex-react-package-creation-1vfs-create-react-libraryvfs-create-widget@mink-opn/build-tokensreact-native-slider-kfplginexpand-react-bridge@everything-registry/sub-chunk-2396@rabailriaz/hisaab-web-portalsync-to-storagetcloud-test-clitailwind-vector-effectsyncbackbaseswebchewoven-challenge-deploywxb-cliwxb-scriptsaasifys3-modulern-tm-notifyrn-session-multiplier-demornttlocksemantic-release-squashsemantic-release-squash3semantic-release-tsheets-testsemantic-release-wo-notessavvato-migrate-mongoresume_fiveresume34567responsive-react-appread-data-filereikamoon-string-library-aarfp-librn-adyen-dropinsuperset-plugin-chart-hello-world2supercluster-googlemaps-adapter-clonestemp-test-semantic-releasesportscale-wifi-connectspotify-ds-sestp-cdksemantic-releasesemantic-release-monoreposemantic-release-monorepo-esmsemantic-release-plussemantic-release-gitmoji-actiontestapawebpack-cli-inittestnpm_lmnvision-camera-plugin-scan-facesgomantic_releasedfeuk-frontenddfeuk-frontend-manualsushi-sdk-ftmweb-yii2migrations-dynamo-dbmigrate-clickhousemigrate-mongomigrate-mongo-altmigrate-mongo-clustermigrate-mongo-semanticmigrate-mongo-ssh-tunnelmigrate-mongo-tsmigrate-mongodb-ogmigrate-ydbmodular-css-coremodular-cssifylib-error
3.0.0

4 years ago

2.2.0

4 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.0.0

8 years ago