it-parallel
Advanced tools
Comparing version 0.0.1 to 1.0.0
@@ -31,5 +31,2 @@ 'use strict' | ||
emitter.on('task-complete', () => { | ||
slotAvailable.resolve() | ||
slotAvailable = defer() | ||
resultAvailable.resolve() | ||
@@ -85,2 +82,5 @@ resultAvailable = defer() | ||
} | ||
slotAvailable.resolve() | ||
slotAvailable = defer() | ||
} | ||
@@ -87,0 +87,0 @@ |
{ | ||
"name": "it-parallel", | ||
"version": "0.0.1", | ||
"version": "1.0.0", | ||
"description": "Takes an (async) iterable that emits promise-returning functions, invokes them in parallel up to the concurrency limit and emits the results as they become available but in the same order as the input", | ||
@@ -40,3 +40,3 @@ "main": "index.js", | ||
}, | ||
"gitHead": "e0bab6f7d4ed8429f36e29e37e6032a66252b790" | ||
"gitHead": "15918832d4c2e37dfe5a7f2227e075b2d4940a5f" | ||
} |
134
test.js
@@ -8,29 +8,57 @@ 'use strict' | ||
const createFn = (ms, result) => { | ||
return async () => { | ||
await delay(ms) | ||
return result | ||
} | ||
} | ||
test('Should execute', async (t) => { | ||
const input = [ | ||
async () => { | ||
await delay(1000) | ||
createFn(1000, 1), | ||
createFn(2000, 2), | ||
createFn(100, 3), | ||
createFn(100, 4) | ||
] | ||
return 1 | ||
}, | ||
async () => { | ||
await delay(2000) | ||
const res = await all(parallel(input, 3)) | ||
return 2 | ||
}, | ||
async () => { | ||
await delay(100) | ||
t.deepEqual(res, [1, 2, 3, 4]) | ||
}) | ||
return 3 | ||
}, | ||
async () => { | ||
await delay(100) | ||
test('Should not exceed concurrency limit', async (t) => { | ||
let running = 0 | ||
let runningMax = 0 | ||
const concurrency = 3 | ||
return 4 | ||
const createFn = (ms, result) => { | ||
return async () => { | ||
running++ | ||
if (running > runningMax) { | ||
runningMax = running | ||
} | ||
await delay(ms) | ||
running-- | ||
return result | ||
} | ||
} | ||
const input = [ | ||
createFn(1000, 1), | ||
createFn(100, 2), | ||
createFn(100, 3), | ||
createFn(10, 4), | ||
createFn(10, 5) | ||
] | ||
const res = await all(parallel(input, 3)) | ||
const res = await all(parallel(input, concurrency)) | ||
t.deepEqual(res, [1, 2, 3, 4]) | ||
t.deepEqual(res, [1, 2, 3, 4, 5]) | ||
t.is(runningMax, concurrency) | ||
}) | ||
@@ -42,8 +70,4 @@ | ||
const input = [ | ||
createFn(100, 1), | ||
async () => { | ||
await delay(100) | ||
return 1 | ||
}, | ||
async () => { | ||
await delay(200) | ||
@@ -53,7 +77,3 @@ | ||
}, | ||
async () => { | ||
await delay(50) | ||
return 3 | ||
} | ||
createFn(50, 3) | ||
] | ||
@@ -70,12 +90,4 @@ | ||
const input = [ | ||
async () => { | ||
await delay(200) | ||
return 1 | ||
}, | ||
async () => { | ||
await delay(100) | ||
return 2 | ||
} | ||
createFn(200, 1), | ||
createFn(100, 2) | ||
] | ||
@@ -90,12 +102,4 @@ | ||
const input = [ | ||
async () => { | ||
await delay(200) | ||
return 1 | ||
}, | ||
async () => { | ||
await delay(100) | ||
return 2 | ||
} | ||
createFn(200, 1), | ||
createFn(100, 2) | ||
] | ||
@@ -110,12 +114,4 @@ const batchSize = -1 | ||
const input = [ | ||
async () => { | ||
await delay(200) | ||
return 1 | ||
}, | ||
async () => { | ||
await delay(100) | ||
return 2 | ||
} | ||
createFn(200, 1), | ||
createFn(100, 2) | ||
] | ||
@@ -130,12 +126,4 @@ const batchSize = 0 | ||
const input = [ | ||
async () => { | ||
await delay(200) | ||
return 1 | ||
}, | ||
async () => { | ||
await delay(100) | ||
return 2 | ||
} | ||
createFn(200, 1), | ||
createFn(100, 2) | ||
] | ||
@@ -150,12 +138,4 @@ const batchSize = '2' | ||
const input = [ | ||
async () => { | ||
await delay(200) | ||
return 1 | ||
}, | ||
async () => { | ||
await delay(100) | ||
return 2 | ||
} | ||
createFn(200, 1), | ||
createFn(100, 2) | ||
] | ||
@@ -162,0 +142,0 @@ const batchSize = 2.5 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
8357
0
216