Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
147 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
id: all-prototype | ||
title: #All | ||
--- | ||
|
||
`Aigle#all` executes the result of the parent instance using `Aigle.all`. | ||
|
||
## Arguments | ||
|
||
## Returns | ||
(Aigle): An Aigle instance | ||
|
||
## Example | ||
|
||
### Array | ||
|
||
```js | ||
const order = []; | ||
const makeDelay = async (num, delay) => { | ||
await Aigle.delay(delay); | ||
order.push(num); | ||
return num; | ||
}; | ||
const tasks = [ | ||
makeDelay(1, 30), | ||
makeDelay(2, 20), | ||
makeDelay(3, 10) | ||
]; | ||
(async () => { | ||
const array = await Aigle.resolve(tasks).all(); | ||
console.log(array); // [1, 2, 3]; | ||
console.log(order); // [3, 2, 1]; | ||
})(); | ||
``` | ||
|
||
```js | ||
const order = []; | ||
const makeDelay = (num, delay) => { | ||
return Aigle.delay(delay) | ||
.then(() => { | ||
order.push(num); | ||
return num; | ||
}); | ||
}; | ||
const tasks = [ | ||
makeDelay(1, 30), | ||
makeDelay(2, 20), | ||
makeDelay(3, 10) | ||
]; | ||
Aigle.resolve(tasks) | ||
.all() | ||
.then(array => { | ||
console.log(array); // [1, 2, 3]; | ||
console.log(order); // [3, 2, 1]; | ||
}); | ||
``` | ||
|
||
### Set | ||
|
||
```js | ||
const tasks = new Set([ | ||
Aigle.delay(10, 1), | ||
Promise.resolve(2), | ||
3, | ||
]); | ||
(async () => { | ||
const array = await Aigle.resolve(tasks).all(); | ||
console.log(array); // [1, 2, 3]; | ||
})(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
--- | ||
id: all | ||
title: All | ||
--- | ||
|
||
`Aigle.all` has the same functionality as `Promise.all`, but it is faster. It runs all tasks on parallel. | ||
|
||
The difference is that if the argument is non-iteratable argument, `Aigle.all` returns an empty array. | ||
|
||
## Arguments | ||
1. tasks (Array|Set): It is the same as the native Promise. | ||
|
||
## Returns | ||
(Aigle): An Aigle instance | ||
|
||
## Example | ||
|
||
### Array | ||
|
||
```js | ||
const order = []; | ||
const makeDelay = async (num, delay) => { | ||
await Aigle.delay(delay); | ||
order.push(num); | ||
return num; | ||
}; | ||
const tasks = [ | ||
makeDelay(1, 30), | ||
makeDelay(2, 20), | ||
makeDelay(3, 10) | ||
]; | ||
(async () => { | ||
const array = await Aigle.all(tasks); | ||
console.log(array); // [1, 2, 3]; | ||
console.log(order); // [3, 2, 1]; | ||
})(); | ||
``` | ||
|
||
```js | ||
const order = []; | ||
const makeDelay = (num, delay) => { | ||
return Aigle.delay(delay) | ||
.then(() => { | ||
order.push(num); | ||
return num; | ||
}); | ||
}; | ||
const tasks = [ | ||
makeDelay(1, 30), | ||
makeDelay(2, 20), | ||
makeDelay(3, 10) | ||
]; | ||
Aigle.all(tasks) | ||
.then(array => { | ||
console.log(array); // [1, 2, 3]; | ||
console.log(order); // [3, 2, 1]; | ||
}); | ||
``` | ||
|
||
### Set | ||
|
||
```js | ||
const tasks = new Set([ | ||
Aigle.delay(10, 1), | ||
Promise.resolve(2), | ||
3, | ||
]); | ||
(async () => { | ||
const array = await Aigle.all(tasks) | ||
console.log(array); // [1, 2, 3]; | ||
})(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters