Socket
Socket
Sign inDemoInstall

@supercharge/promise-pool

Package Overview
Dependencies
0
Maintainers
3
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.3.0 to 2.3.1

9

dist/promise-pool-executor.js

@@ -292,2 +292,7 @@ 'use strict';

async waitForProcessingSlot() {
/**
* We’re using a while loop here because it’s possible to decrease the pool’s
* concurrency at runtime. We need to wait for as many tasks as needed to
* finish processing before moving on to process the remaining tasks.
*/
while (this.hasReachedConcurrencyLimit()) {

@@ -330,3 +335,3 @@ await Promise.race(this.tasks());

async createTaskFor(item, index) {
return this.handler(item, index, this);
return Promise.resolve(this.handler(item, index, this));
}

@@ -367,3 +372,3 @@ /**

}
return this.hasErrorHandler()
this.hasErrorHandler()
? await this.runErrorHandlerFor(error, item)

@@ -370,0 +375,0 @@ : this.saveErrorFor(error, item);

{
"name": "@supercharge/promise-pool",
"description": "Map-like, concurrent promise processing for Node.js",
"version": "2.3.0",
"version": "2.3.1",
"author": "Marcus Pöhls <marcus@superchargejs.com>",

@@ -10,9 +10,9 @@ "bugs": {

"devDependencies": {
"@supercharge/eslint-config-typescript": "~2.2.0",
"@supercharge/eslint-config-typescript": "~2.3.0",
"@supercharge/tsconfig": "~1.0.0",
"c8": "~7.11.3",
"eslint": "~8.17.0",
"expect": "~28.1.1",
"typescript": "~4.7.3",
"uvu": "~0.5.3"
"c8": "~7.12.0",
"eslint": "~8.21.0",
"expect": "~28.1.3",
"typescript": "~4.7.4",
"uvu": "~0.5.6"
},

@@ -50,3 +50,4 @@ "engines": {

"lint:fix": "npm run lint -- --fix",
"test": "npm run build && npm run lint && npm run test:coverage",
"test": "npm run build && npm run test:coverage",
"test:full": "npm run build && npm run lint && npm run test:coverage",
"test:run": "uvu",

@@ -53,0 +54,0 @@ "test:coverage": "c8 --include=dist npm run test:run && npm run test:report",

@@ -156,4 +156,4 @@ <div align="center">

## Callback for Started and Finished Task
You can receive a callback when any task has started with `.onTaskStarted()` with the `item` has starting this process, with `percentage` of progress the items that has started, `activeTasks` that is processing and `finishedTasks`:
## Callback for Started and Finished Tasks
You can use the `onTaskStarted` and `onTaskFinished` methods to hook into the processing of tasks. The provided callback for each method will be called when a task started/finished processing:

@@ -166,7 +166,12 @@

.for(users)
.onTaskStarted((item, percentage, activeTasks, finishedTasks) => {
console.log(`Progress: ${percentage}%`)
console.log(`Active tasks: ${activeTasks.length}`)
console.log(`Finished tasks: ${finishedTasks.length}`)
.onTaskStarted((item, pool) => {
console.log(`Progress: ${pool.processedPercentage()}%`)
console.log(`Active tasks: ${pool.processedItems().length}`)
console.log(`Active tasks: ${pool.activeTasksCount()}`);
console.log(`Finished tasks: ${pool.processedItems().length}`)
console.log(`Finished tasks: ${pool.processedCount()}`)
})
.onTaskFinished((item, pool) => {
// update a progress bar or something else :)
})
.process(async (user, index, pool) => {

@@ -177,3 +182,3 @@ // processes the `user` data

You can also receive callback `.onTaskFinished()`, with parameter `percentage` of progress the items that has finished:
You can also chain multiple `onTaskStarted` and `onTaskFinished` handling (in case you want to separate some functionality):

@@ -185,7 +190,6 @@ ```js

.for(users)
.onTaskFinished((item, percentage, activeTasks, finishedTasks) => {
console.log(`Progress: ${percentage}%`)
console.log(`Active tasks: ${activeTasks.length}`)
console.log(`Finished tasks: ${finishedTasks.length}`)
})
.onTaskStarted(() => {})
.onTaskStarted(() => {})
.onTaskFinished(() => {})
.onTaskFinished(() => {})
.process(async (user, index, pool) => {

@@ -192,0 +196,0 @@ // processes the `user` data

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc