|
|
@@ -47,14 +47,15 @@ describe('Source', function () {
|
|
|
)
|
|
|
})
|
|
|
|
|
|
- it('should run async computations', async () => {
|
|
|
+ it('should run ordered async', async () => {
|
|
|
await fc.assert(
|
|
|
- fc.asyncProperty(fc.array(fc.integer()), async (arr) => {
|
|
|
+ fc.asyncProperty(fc.array(fc.integer()), fc.integer(1, 50), async (arr, concurrencyLevel) => {
|
|
|
+ const timeout = () => (1 + (0 | (Math.random() * 4)))
|
|
|
const result = await Source.fromArray(arr)
|
|
|
- .mapAsync(50, v => { return new Promise(resolve => setTimeout(() => resolve(v * 2), 2)) })
|
|
|
- .into(Sink.sum)
|
|
|
+ .mapAsync(concurrencyLevel, v => { return new Promise(resolve => setTimeout(() => resolve(v), timeout())) })
|
|
|
+ .into(Sink.reduce<number, number[]>((acc, b) => ([...acc, b]), []))
|
|
|
.run()
|
|
|
- assert.equal(result, 2 * arr.reduce((a, b) => a + b, 0))
|
|
|
+ assert.deepEqual(result, arr)
|
|
|
})
|
|
|
)
|
|
|
})
|
|
|
@@ -71,19 +72,6 @@ describe('Source', function () {
|
|
|
)
|
|
|
})
|
|
|
|
|
|
- it('should run async computations while keeping order', async () => {
|
|
|
- await fc.assert(
|
|
|
- fc.asyncProperty(fc.array(fc.integer()), fc.integer(1, 50), async (arr, concurrencyLevel) => {
|
|
|
- const timeout = () => (1 + (0 | (Math.random() * 4)))
|
|
|
- const result = await Source.fromArray(arr)
|
|
|
- .mapAsync(concurrencyLevel, v => { return new Promise(resolve => setTimeout(() => resolve(v), timeout())) })
|
|
|
- .into(Sink.reduce<number, number[]>((acc, b) => ([...acc, b]), []))
|
|
|
- .run()
|
|
|
- assert.deepEqual(result, arr)
|
|
|
- })
|
|
|
- )
|
|
|
- })
|
|
|
-
|
|
|
it('should filter elements', async () => {
|
|
|
await fc.assert(
|
|
|
fc.asyncProperty(fc.array(fc.integer()), async (arr) => {
|