Skip to content

Commit 762beee

Browse files
committed
Merge pull request #59 from Sykander/develop
Release 1.0.3
2 parents ceb8a17 + 3897fdf commit 762beee

22 files changed

+478
-176
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,23 @@ class AsyncArray extends Array {...}
2727
* Async Find Index
2828
* Async For Each
2929
* Async Map
30+
* Async Sort
3031

31-
### Async Filter
32+
### [Async Filter](https://github.com/Sykander/iterable-async/wiki/Async-Filter)
3233

3334
Filter an iterable object asynchronously
3435
```
3536
async function asyncFilter(callback, [thisArg]) {...}
3637
```
3738

38-
### Async Find
39+
### [Async Find](https://github.com/Sykander/iterable-async/wiki/Async-Find)
3940

4041
Find an item in an iterable object asynchronously
4142
```
4243
async function asyncFind(callback, [thisArg]) {...}
4344
```
4445

45-
### Async Find Index
46+
### [Async Find Index](https://github.com/Sykander/iterable-async/wiki/Async-Find-Index)
4647

4748
Find an item's index in an iterable object asynchronously
4849
```
@@ -56,13 +57,19 @@ Loop over an iterable object asynchronously
5657
async function asyncForEach(callback, [thisArg]) {...}
5758
```
5859

59-
### Async Map
60+
### [Async Map](https://github.com/Sykander/iterable-async/wiki/Async-Map)
6061

6162
Map an iterable object asynchronously
6263
```
6364
async function asyncMap(callback, [thisArg]) {...}
6465
```
6566

67+
### [Async Sort](https://github.com/Sykander/iterable-async/wiki/Async-Sort)
68+
69+
Sort an iterable object asynchronously
70+
```
71+
async function asyncSort(callback) {...}
72+
```
6673

6774
## Development
6875

@@ -86,4 +93,4 @@ npm test
8693

8794
### Commit Rules
8895

89-
* All commits should pass the lint check commands
96+
* All commits should pass the lint check commands

docs/playground.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ const {
44
asyncFindIndex,
55
asyncFilter,
66
asyncForEach,
7-
asyncMap
7+
asyncMap,
8+
asyncSort
89
} = require('iterable-async');

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iterable-async",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "A Collection of useful patterns.",
55
"main": "src",
66
"scripts": {
@@ -35,5 +35,12 @@
3535
"pre-commit": "npm run lint:check"
3636
}
3737
},
38+
"keywords": [
39+
"promise",
40+
"iterable",
41+
"async",
42+
"array",
43+
"methods"
44+
],
3845
"runkitExampleFilename": "docs/playground.js"
3946
}

src/async-array.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ const asyncMap = require('./async-map'),
22
asyncForEach = require('./async-for-each'),
33
asyncFilter = require('./async-filter'),
44
asyncFind = require('./async-find'),
5-
asyncFindIndex = require('./async-find-index');
5+
asyncFindIndex = require('./async-find-index'),
6+
asyncSort = require('./async-sort');
67

78
/**
8-
* Create new constructor for Async Array
9+
* Async Array
10+
* ===========
11+
* Array like object with access to async array methods
912
* @type {AsyncArray}
1013
*/
1114
class AsyncArray extends Array {}
@@ -15,6 +18,7 @@ class AsyncArray extends Array {}
1518
(AsyncArray.prototype.asyncFindIndex = asyncFindIndex),
1619
(AsyncArray.prototype.asyncFilter = asyncFilter),
1720
(AsyncArray.prototype.asyncForEach = asyncForEach),
18-
(AsyncArray.prototype.asyncMap = asyncMap);
21+
(AsyncArray.prototype.asyncMap = asyncMap),
22+
(AsyncArray.prototype.asyncSort = asyncSort);
1923

2024
module.exports = AsyncArray;

src/async-filter.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
const { mapIterable } = require('./helpers'),
1+
const { mapIterable, filterIterable } = require('./helpers'),
22
{ noParam } = require('./constants'),
33
{ validateIsIterable, validateIsFunction } = require('./validation');
44

55
/**
66
* Async Filter
7+
* ============
78
* Filter an iterable object asynchronously and resolve when all callbacks are resolved
89
* @async
910
* @param {Function} callback - callback(currentValue, index, array)
@@ -17,7 +18,8 @@ module.exports = async function asyncFilter(callback, thisArg = noParam) {
1718
validateIsFunction(callback);
1819
validateIsIterable(collection);
1920

20-
const checks = await Promise.all(mapIterable(collection, callback));
21-
22-
return [...collection].filter((item, index) => checks[index]);
21+
return filterIterable(
22+
collection,
23+
await Promise.all(mapIterable(collection, callback))
24+
);
2325
};

src/async-find-index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { mapIterable } = require('./helpers'),
44

55
/**
66
* Async Find Index
7+
* ================
78
* Find an item's index in an iterable object asynchronously and resolve when found or all callbacks resolve
89
* @async
910
* @param {Function} callback - callback(currentValue, index, array)

src/async-find.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { mapIterable } = require('./helpers'),
44

55
/**
66
* Async Find
7+
* ==========
78
* Find an item in an iterable object asynchronously and resolve when found or all callbacks resolve
89
* @async
910
* @param {Function} callback - callback(currentValue, index, array)
@@ -19,18 +20,20 @@ module.exports = async function asyncFind(callback, thisArg = noParam) {
1920

2021
const tasks = mapIterable(collection, callback);
2122

22-
const index = await Promise.race([
23-
Promise.race(
24-
tasks.map(async (task, index) => {
25-
const checkIsFound = await task;
23+
return collection[
24+
await Promise.race([
25+
Promise.race(
26+
tasks.map(async (task, index) => {
27+
const checkIsFound = await task;
2628

27-
return new Promise(resolve => checkIsFound && resolve(index));
28-
})
29-
),
30-
Promise.all(tasks).then(taskResults =>
31-
taskResults.findIndex(result => result)
32-
)
33-
]);
34-
35-
return collection[index];
29+
return new Promise(
30+
resolve => checkIsFound && resolve(index)
31+
);
32+
})
33+
),
34+
Promise.all(tasks).then(taskResults =>
35+
taskResults.findIndex(result => result)
36+
)
37+
])
38+
];
3639
};

src/async-for-each.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { mapIterable } = require('./helpers'),
44

55
/**
66
* Async For Each
7+
* ==============
78
* Loop over an iterable object asynchronously and resolve when all callbacks are resolved
89
* @async
910
* @param {Function} callback - callback(currentValue, index, array)

src/async-map.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { mapIterable } = require('./helpers'),
44

55
/**
66
* Async Map
7+
* =========
78
* Map an iterable object asynchronously and resolve when all callbacks are resolved
89
* @async
910
* @param {Function} callback - callback(currentValue, index, array)

0 commit comments

Comments
 (0)