Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

await-foreach

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

await-foreach

async/await with forEach

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

async/await with forEach | Используем async/await с forEach

About | Что это

Это функция для асинхронного перебора массивов

Весь код представлен ниже. Можете его просто скопировать в свое приложение. Или можете установить с npm

async function awaitForEach(array, asyncCallback) {
  for (let index = 0; index < array.length; index++) {
    await asyncCallback(array[index], index, array)
  }
}

Install | Установка

npm

npm install --save await-foreach

yarn

yarn add await-foreach

awaitForEach(array, asyncCallback) ⇒ Promise

Kind: global function

ParamTypeDescription
arrayArrayМассив элементы которого подлежат перебору
asyncCallbackfunctionАсинхронная функция. Передаются параметры как в методе Array.forEach Функция должна всегда возвращать Promise

Example

// with async/await
const awaitForEach = require('await-foreach')

...

await awaitForEach([1, 2, 3], async (item, index, arr) => {
  await Promise.resolve()
})
console.log('end')

Example

// with promise
const awaitForEach = require('await-foreach')

...

awaitForEach([1, 2, 3], (item, index, arr) => {
  // Должна возвращать Promise
  return Promise.resolve()
}).then(() => {
  console.log('end')
})

Keywords

FAQs

Package last updated on 14 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc