All Projects → supercharge → Promise Pool

supercharge / Promise Pool

Licence: mit
Map-like, concurrent promise processing

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Promise Pool

P Map
Map over promises concurrently
Stars: ✭ 639 (+147.67%)
Mutual labels:  async, concurrency, promises
Functional Promises
Write code like a story w/ a powerful Fluent (function chaining) API
Stars: ✭ 141 (-45.35%)
Mutual labels:  hacktoberfest, async, promises
Tascalate Concurrent
Implementation of blocking (IO-Bound) cancellable java.util.concurrent.CompletionStage and related extensions to java.util.concurrent.ExecutorService-s
Stars: ✭ 144 (-44.19%)
Mutual labels:  async, concurrency, promises
Promise Fun
Promise packages, patterns, chat, and tutorials
Stars: ✭ 3,779 (+1364.73%)
Mutual labels:  async, concurrency, promises
Kovenant
Kovenant. Promises for Kotlin.
Stars: ✭ 657 (+154.65%)
Mutual labels:  async, concurrency, promises
Swimmer
🏊 Swimmer - An async task pooling and throttling utility for JS
Stars: ✭ 94 (-63.57%)
Mutual labels:  async, concurrency, promises
Ava
Node.js test runner that lets you develop with confidence 🚀
Stars: ✭ 19,458 (+7441.86%)
Mutual labels:  hacktoberfest, async, concurrency
Akka
Build highly concurrent, distributed, and resilient message-driven applications on the JVM
Stars: ✭ 11,938 (+4527.13%)
Mutual labels:  hacktoberfest, concurrency
Django Loci
Reusable Django app for storing geographic and indoor coordinates. Maintained by the OpenWISP Project.
Stars: ✭ 164 (-36.43%)
Mutual labels:  hacktoberfest, map
Zio
ZIO — A type-safe, composable library for async and concurrent programming in Scala
Stars: ✭ 3,167 (+1127.52%)
Mutual labels:  concurrency, promises
Swoole Bundle
Symfony Swoole Bundle
Stars: ✭ 201 (-22.09%)
Mutual labels:  hacktoberfest, async
Bikedeboa
A (Progressive) Web App to find, map and review bike parkings in the cities of Brazil.
Stars: ✭ 54 (-79.07%)
Mutual labels:  hacktoberfest, map
Actix Extras
A collection of additional crates supporting the actix and actix-web frameworks.
Stars: ✭ 190 (-26.36%)
Mutual labels:  hacktoberfest, async
Joshuto
ranger-like terminal file manager written in Rust
Stars: ✭ 224 (-13.18%)
Mutual labels:  hacktoberfest, concurrency
Madelineproto
Async PHP client/server API for the telegram MTProto protocol
Stars: ✭ 1,776 (+588.37%)
Mutual labels:  hacktoberfest, async
Bastion
Highly-available Distributed Fault-tolerant Runtime
Stars: ✭ 2,333 (+804.26%)
Mutual labels:  hacktoberfest, concurrency
Brawlstats
(A)sync python wrapper for the Brawl Stars API
Stars: ✭ 68 (-73.64%)
Mutual labels:  hacktoberfest, async
Trilogy
TypeScript SQLite layer with support for both native C++ & pure JavaScript drivers.
Stars: ✭ 195 (-24.42%)
Mutual labels:  hacktoberfest, async
ProtoPromise
Robust and efficient library for management of asynchronous operations in C#/.Net.
Stars: ✭ 20 (-92.25%)
Mutual labels:  promises, concurrency
Maps
🌍🌏🌎 The whole world fits inside your cloud!
Stars: ✭ 253 (-1.94%)
Mutual labels:  hacktoberfest, map


Promise Pool

Map-like, concurrent promise processing for Node.js.


Installation · Docs · Usage



Latest Version Monthly downloads

Follow @marcuspoehls and @superchargejs for updates!


Installation

npm i @supercharge/promise-pool

Docs

Find all the details and available methods in the extensive Supercharge docs.

Usage

Using the promise pool is pretty straightforward. The package exposes a class and you can create a promise pool instance using the fluent interface.

Here’s an example using a concurrency of 2:

const PromisePool = require('@supercharge/promise-pool')

const users = [
  { name: 'Marcus' },
  { name: 'Norman' },
  { name: 'Christian' }
]

const { results, errors } = await PromisePool
  .withConcurrency(2)
  .for(users)
  .process(async data => {
    const user = await User.createIfNotExisting(data)

    return user
  })

The promise pool uses a default concurrency of 10:

await PromisePool
  .for(users)
  .process(async data => {
    // processes 10 items in parallel by default
  })

Bring Your Own Error Handling

The promise pool allows for custom error handling. You can take over the error handling by implementing an error handler using the .handleError(handler).

If you provide an error handler, the promise pool doesn’t collect any errors. You must then collect errors yourself.

Providing a custom error handler allows you to exit the promise pool early by throwing inside the error handler function. Throwing errors is in line with Node.js error handling using async/await.

try {
  const errors = []

  const { results } = await PromisePool
    .for(users)
    .withConcurrency(4)
    .handleError(async (error, user) => {
      if (error instanceof ValidationError) {
        errors.push(error) // you must collect errors yourself
        return
      }

      if (error instanceof ThrottleError) { // Execute error handling on specific errors
        await retryUser(user)
        return
      }

      throw error // Uncaught errors will immediately stop PromisePool
    })
    .process(async data => {
      // the harder you work for something,
      // the greater you’ll feel when you achieve it
    })

  await handleCollected(errors) // this may throw

  return { results }
} catch (error) {
  await handleThrown(error)
}

Contributing

  1. Create a fork
  2. Create your feature branch: git checkout -b my-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request 🚀

License

MIT © Supercharge


superchargejs.com  ·  GitHub @superchargejs  ·  Twitter @superchargejs

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].