New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

sync-async-loops

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sync-async-loops

a tool to help you controll asynchronous loops, speed things up, and make sure certain parts are executed in an orderly fashion while keeping the asynchronous nature of the loop

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

sync-async-loops

The library purpose is to help you synchronise asynchronous loops in order to obtain a better performance

Synchronizer

const Synchronizer = require ('sync-async-loops')

const synchronizer = new Synchronizer()

synchronizer.sync(index)

Create a point from which the loops will be executed one by one,starting with the first index

It behaves as if the loop just started.

synchronizer.syncOnce(fn, param1, param2, param3........)

Calls an async function using the provided params, and for each call, it returns the same promise, making sure to make only one call for all the items that are being processed

Example 1

await Promise.all(
    data.map(async (item, index) => {
        resultsArrOne.push(item)
        await synchronizer.runOnce(sleepRandom, 'sleep', 'param1', 'param2')
        await synchronizer.sync(index)
        resultsArrTwo.push(item)
    })
)

Example 2

const findProjectsByUserNames = async (userNames) => {  
    const users = await usersRepositoy.findUsersByName(userNames)
    const userIds= [] 
    const projects = []
    await Promise.all(
        users.map(async (user, index) => {
            userIds.push(user.id)
            await synchronizer.sync(index)
            const userProjects = await synchronizer.runOnce(findProjectsByUserIds,userIds)
            projects = projects.concat(userProjects)
        })
    )
    return projects
}

FAQs

Package last updated on 31 Jul 2023

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