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-portallamassu-configsiex-sdkfrdrk-js-semaphoreinteractorkahnlabnetic-dbkrown_login_librarykrulkrul-clikrul-scriptshot-zone-vuehotkey-mapperhexo-search-algoliahexo-meilisearchhexyun.helpersignore-this-dot-jsmd-vditorlib-errormigrate-mongomigrate-mongo-altmigrate-mongo-clustermigrate-mongo-semanticmigrate-mongo-ssh-tunnelmigrate-mongo-tsmigrate-mongodb-ogmigrate-clickhousemigrate-ydbmigrations-dynamo-dbmodular-css-coremodular-cssifynodecg-screenshot-testernois-react-toastp-thunkp-funp-each-series-cjspapuap-suitep-promise-utilspayutestingphoenix-app-creatornv3-componentnv3-utilsnv4-utilsnumhandlernpm_one_12_34_1_npm_one_1_2_3npm_one_2_2npm_qwertynpm-package-mentorcheckobaraorbit-db-storeorbit-webmongo-ratormongo-upmongo-up-1ipfs-logmacos-keyboard-shortcutslvbyte-cdn
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