Skip to content

Commit

Permalink
docs(all): add all docs [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
suguru03 committed Sep 22, 2018
1 parent 2cf7164 commit 92f3db1
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 1 deletion.
70 changes: 70 additions & 0 deletions docs/apis/all-prototype.md
@@ -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];
})();
```
72 changes: 72 additions & 0 deletions docs/apis/all.md
@@ -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];
})();
```
6 changes: 5 additions & 1 deletion website/sidebars.json
Expand Up @@ -4,6 +4,10 @@
"Usage": ["install"]
},
"api-docs": {
"Core": ["apis/aigle"]
"Core": [
"apis/aigle",
"apis/all",
"apis/all-prototype"
]
}
}

0 comments on commit 92f3db1

Please sign in to comment.