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

epic-async

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

epic-async

lightweight async foreach thing with typings written at 1am.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

epic-async

lightweight async foreach thing with typings written at 1am.

import { forEach } from 'epic-async';

// each task takes a different amount of time to complete
const array = [1000, 5000, 100, 2000];

async function go() {
    // however, it will not continue until the previous iteration completes
    // you can also use .then instead of await if you want but i don't see why you'd do that
    // or you could do neither
    await forEach(array, async (value, callback, i) => {
        console.log(`wait for ${value}ms. index: ${i}`);
        await stall(value as number); // stall/wait "value" milliseconds before continuing to the next value in the array
        callback();
    });
    console.log('done');
}

function stall(time: number) {
    return new Promise(resolve => setTimeout(resolve, time));
}

go();
wait for 1000ms. Index: 0
wait for 5000ms. Index: 1
wait for 100ms. Index: 2
wait for 2000ms. index: 3
done

FAQs

Package last updated on 10 Apr 2021

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