0.0.1-alpha.6 • Published 2 years ago

promise_array_parallel v0.0.1-alpha.6

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

promise_array_parallel

License: MIT PRs Welcome Created by GunseiKPaseri

GitHub issues GitHub last commit

deno.land/x deno doc Package Dependencies Maintaind? nest.land

npm version npm

  • Manage Promise[].
    • Parallel execution of async function
    • Semaphore

There are no dependent packages, so it can be used in both Deno & npm environments.

Example

See ./src/promise_array_parallel.test.ts

Node

npm install promise_array_parallel

make example.js

const PromiseArray = require('promise_array_parallel').PromiseArray

const sleep = (ms = 0) =>
  new Promise((res) => setTimeout(res, ms));

PromiseArray
    .from([...new Array(40)].map((_, i) => i < 20 ? 20 - i : i - 20))
    .parallelWork(async({idx, value}) => {
        await sleep(value * 10)
        console.log(idx)
    })
    .parallelWork(async({idx}) => {
        console.log("    " + idx)
    }, { priority: "INDEX" })
    
node ./example.js

Deno

import {PromiseArray} from 'https://deno.land/x/promise_array_parallel/mod.ts'

const sleep = (ms = 0) =>
  new Promise((res) => setTimeout(res, ms));


PromiseArray
    .from([...new Array(40)].map((_, i) => i < 20 ? 20 - i : i - 20))
    .parallelWork(async({idx, value}) => {
        await sleep(value * 10)
        console.log(idx)
    })
    .parallelWork(async({idx}) => {
        console.log("    " + idx)
    }, { priority: "INDEX" })
    

Develop This package

This package is developed in Deno; it is recommended to install Deno.

Lint / Format / test

deno task test

Generate NPM Package & Publish

deno task dnt

Automatically published when you push the tagged main branch