New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

yakugen

Package Overview
Dependencies
Maintainers
0
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yakugen

dynamic promise execution

latest
Source
npmnpm
Version
0.0.20
Version published
Weekly downloads
16
-48.39%
Maintainers
0
Weekly downloads
 
Created
Source
nostalgia

About

yakugen (yaku-gen) is a dynamic promise executor for Node.js. yakugen dynamically adjusts Promise concurrency to maximize performance whilst meeting target CPU & Event Loop Utilization metrics.

API Reference: https://ragrag.github.io/yakugen

Installing

npm install yakugen

Examples

Usage

async function asyncTask(item){
    await doSomething(item);
}

const items = new Array(1000).fill(Math.random());
const tasks = items.map(it => async () => {
    return asyncTask(it);
});

const resAll = await Yakugen.all(tasks);
const resAllSettled = await Yakugen.allSettled(tasks);

Controlling Concurrency Limits

async function asyncTask(item){
    await doSomething(item);
}

const items = new Array(1000).fill(Math.random());
const tasks = items.map(it => async () => {
    return asyncTask(it);
});

const res = await Yakugen.all(tasks, { minConcurrency: 5, maxConcurrency: 50 });

Yakugen defaults:

  • minConcurrency: 1
  • maxConcurrency: 500

Controlling Metrics Targets

async function asyncTask(item){
    await doSomething(item);
}

const items = new Array(1000).fill(Math.random());
const tasks = items.map(it => async () => {
    return asyncTask(it);
});

const res = await Yakugen.all(tasks, { targets: { cpuUtilization: 60, eventLoopUtilization: 65, eventLoopDelayMs: 100 } });

Yakugen defaults:

  • cpuUtilization: 75
  • eventLoopUtilization: 75
  • eventLoopDelayMs: 150

Custom Metrics Targets

async function asyncTask(item){
    await doSomething(item);
}

const items = new Array(1000).fill(Math.random());
const tasks = items.map(it => async () => {
    return asyncTask(it);
});

const res = await Yakugen.all(tasks, {
    targets: {
        custom: {
            connectionPool: {
                current: () => db.currentConnections(),
                target: db.poolSize() / 2,
            },
            // ... add more custom metrics
        },
    },
});

In addition to cpuUtilization, eventLoopUtilization, eventLoopDelayMs Yakugen will also adjust concurrency based on provided custom metrics.

Track Progress

async function asyncTask(item){
    await doSomething(item);
}

const items = new Array(1000).fill(Math.random());
const tasks = items.map(it => async () => {
    return asyncTask(it);
});

const res = await Yakugen.all(tasks, {
    onProgress: (processed, metrics, currentConcurrency) => {
        console.log(processed, metrics, currentConcurrency);
    },
});

Keywords

concurrency

FAQs

Package last updated on 09 Aug 2024

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