Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit f1077f7

Browse files
author
Alan Shaw
authored
refactor: async iterables (#567)
* refactor: async iterables * fix: browser check not work for http client
1 parent f48dcad commit f1077f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+1462
-3530
lines changed

Diff for: SPEC/BITSWAP.md

+12-19
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
* [bitswap.wantlist](#bitswapwantlist)
44
* [bitswap.stat](#bitswapstat)
55

6-
### ⚠️ Note
7-
Although not listed in the documentation, all the following APIs that actually return a **promise** can also accept a **final callback** parameter.
8-
96
### `bitswap.wantlist`
107

118
> Returns the wantlist, optionally filtered by peer ID
@@ -16,23 +13,18 @@ Although not listed in the documentation, all the following APIs that actually r
1613

1714
| Type | Description |
1815
| -------- | -------- |
19-
| `Promise<Object>` | An object representing the wantlist |
20-
21-
the returned object contains the following keys:
22-
23-
- `Keys` An array of objects containing the following keys:
24-
- `/` A string multihash
16+
| `Promise<CID[]>` | An array of [CID][cid]s currently in the wantlist |
2517

2618
**Example:**
2719

2820
```JavaScript
2921
const list = await ipfs.bitswap.wantlist()
3022
console.log(list)
31-
// { Keys: [{ '/': 'QmHash' }] }
23+
// [ CID('QmHash') ]
3224

3325
const list2 = await ipfs.bitswap.wantlist(peerId)
3426
console.log(list2)
35-
// { Keys: [{ '/': 'QmHash' }] }
27+
// [ CID('QmHash') ]
3628
```
3729

3830
A great source of [examples][] can be found in the tests for this API.
@@ -51,11 +43,11 @@ Note: `bitswap.stat` and `stats.bitswap` can be used interchangeably.
5143
| -------- | -------- |
5244
| `Promise<Object>` | An object that contains information about the bitswap agent |
5345

54-
the returned object contains the following keys:
46+
The returned object contains the following keys:
5547

5648
- `provideBufLen` is an integer.
57-
- `wantlist` (array of CIDs)
58-
- `peers` (array of peer IDs)
49+
- `wantlist` (array of [CID][cid]s)
50+
- `peers` (array of peer IDs as [CID][cid] instances)
5951
- `blocksReceived` is a [BigNumber Int][1]
6052
- `dataReceived` is a [BigNumber Int][1]
6153
- `blocksSent` is a [BigNumber Int][1]
@@ -70,21 +62,22 @@ const stats = await ipfs.bitswap.stat()
7062
console.log(stats)
7163
// {
7264
// provideBufLen: 0,
73-
// wantlist: [ { '/': 'QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM' } ],
65+
// wantlist: [ CID('QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM') ],
7466
// peers:
75-
// [ 'QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
76-
// 'QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
77-
// 'QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd' ],
67+
// [ CID('QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM'),
68+
// CID('QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu'),
69+
// CID('QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd') ],
7870
// blocksReceived: 0,
7971
// dataReceived: 0,
8072
// blocksSent: 0,
8173
// dataSent: 0,
8274
// dupBlksReceived: 0,
83-
// dupDataReceived: 0
75+
// dupDataReceived: 0
8476
// }
8577
```
8678

8779
A great source of [examples][] can be found in the tests for this API.
8880

8981
[1]: https://github.com/MikeMcl/bignumber.js/
9082
[examples]: https://github.com/ipfs/interface-ipfs-core/blob/master/src/bitswap
83+
[cid]: https://www.npmjs.com/package/cids

Diff for: SPEC/BLOCK.md

+16-9
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
* [block.rm](#blockrm)
66
* [block.stat](#blockstat)
77

8-
### ⚠️ Note
9-
Although not listed in the documentation, all the following APIs that actually return a **promise** can also accept a **final callback** parameter.
10-
118
#### `block.get`
129

1310
> Get a raw IPFS block.
@@ -114,22 +111,32 @@ A great source of [examples][] can be found in the tests for this API.
114111

115112
`options` is an Object that can contain the following properties:
116113

117-
- force (boolean): Ignores nonexistent blocks.
118-
- quiet (boolean): write minimal output
114+
- `force` (boolean): Ignores nonexistent blocks.
115+
- `quiet` (boolean): write minimal output
119116

120117
**Returns**
121118

122119
| Type | Description |
123120
| -------- | -------- |
124-
| `Promise<Array>` | An array of objects containing hash and (potentially) error strings |
121+
| `AsyncIterable<Object>` | An async iterable that yields objects containing hash and (potentially) error strings |
125122

126-
Note: If an error string is present for a given object in the returned array, the block with that hash was not removed and the string will contain the reason why, for example if the block was pinned.
123+
Each object yielded is of the form:
124+
125+
```js
126+
{
127+
hash: string,
128+
error: string
129+
}
130+
```
131+
132+
Note: If an error string is present for a given object, the block with that hash was not removed and the string will contain the reason why, for example if the block was pinned.
127133

128134
**Example:**
129135

130136
```JavaScript
131-
const result = await ipfs.block.rm(cid)
132-
console.log(result[0].hash)
137+
for await (const result of ipfs.block.rm(cid)) {
138+
console.log(result.hash)
139+
}
133140
```
134141

135142
A great source of [examples][] can be found in the tests for this API.

Diff for: SPEC/BOOTSTRAP.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@
44
the addresses of the bootstrap nodes. These are the trusted peers from
55
which to learn about other peers in the network.
66

7-
> Only edit this list if you understand the risks of adding or removing nodes from this list.
7+
> Only edit this list if you understand the risks of adding or removing nodes
88
99
* [bootstrap.add](#bootstrapadd)
1010
* [bootstrap.list](#bootstraplist)
1111
* [bootstrap.rm](#bootstraprm)
1212

13-
### ⚠️ Note
14-
Although not listed in the documentation, all the following APIs that actually return a **promise** can also accept a **final callback** parameter.
15-
1613
#### `bootstrap.add`
1714

1815
> Add a peer address to the bootstrap list

Diff for: SPEC/CONFIG.md

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
* [config.profiles.list](#configprofileslist)
77
* [config.profiles.apply](#configprofilesapply)
88

9-
### ⚠️ Note
10-
Although not listed in the documentation, all the following APIs that actually return a **promise** can also accept a **final callback** parameter.
11-
129
#### `config.get`
1310

1411
> Returns the currently being used config. If the daemon is off, it returns the stored config.

Diff for: SPEC/DAG.md

-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ _Explore the DAG API through interactive coding challenges in our ProtoSchool tu
1010
- _[P2P data links with content addressing](https://proto.school/#/basics/) (beginner)_
1111
- _[Blogging on the Decentralized Web](https://proto.school/#/blog/) (intermediate)_
1212

13-
### ⚠️ Note
14-
Although not listed in the documentation, all the following APIs that actually return a **promise** can also accept a **final callback** parameter.
15-
1613
#### `dag.put`
1714

1815
> Store an IPLD format node

0 commit comments

Comments
 (0)