Skip to content

Commit 0e9a1a7

Browse files
authored
refactor: switch to async (#15)
BREAKING CHANGE: Switch to using async/await
1 parent a122ec0 commit 0e9a1a7

File tree

5 files changed

+513
-503
lines changed

5 files changed

+513
-503
lines changed

Diff for: README.md

+18-12
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@
1717

1818
## Table of Contents
1919

20-
- [Install](#install)
21-
- [Usage](#usage)
22-
- [API](#api)
23-
- [Contribute](#contribute)
24-
- [License](#license)
20+
- [Lead Maintainer](#lead-maintainer)
21+
- [Table of Contents](#table-of-contents)
22+
- [Install](#install)
23+
- [Usage](#usage)
24+
- [API](#api)
25+
- [Setup](#setup)
26+
- [Get](#get)
27+
- [Put](#put)
28+
- [Unsubscribe](#unsubscribe)
29+
- [Contribute](#contribute)
30+
- [License](#license)
2531

2632
### Install
2733

@@ -62,22 +68,21 @@ const dsPubsub = new DatastorePubsub(pubsub, datastore, peerId, validator)
6268
#### Get
6369

6470
```js
65-
dsPubsub.get(key, callback)
71+
const buf = await dsPubsub.get(key)
6672
```
6773

6874
Try to subscribe a topic with Pubsub and receive the current local value if available.
6975

7076
Arguments:
7177

7278
- `key` (Buffer): a key representing a unique identifier of the object to subscribe.
73-
- `callback` (function): operation result.
7479

75-
`callback` must follow `function (err, data) {}` signature, where `err` is an error if the operation was not successful. If no `err` is received, a `data` is received containing the most recent known record stored (`Buffer`).
80+
Returns `Promise<Buffer>` containing the most recent known record stored.
7681

7782
#### Put
7883

7984
```js
80-
dsPubsub.put(key, val, callback)
85+
await dsPubsub.put(key, val)
8186
```
8287

8388
Publishes a value through pubsub.
@@ -86,14 +91,13 @@ Arguments:
8691

8792
- `key` (Buffer): a key representing a unique identifier of the object to publish.
8893
- `val` (Buffer): value to be propagated.
89-
- `callback` (function): operation result.
9094

91-
`callback` must follow `function (err) {}` signature, where `err` is an error if the operation was not successful.
95+
Returns `Promise<void>`
9296

9397
#### Unsubscribe
9498

9599
```js
96-
dsPubsub.unsubscribe(key, callback)
100+
await dsPubsub.unsubscribe(key)
97101
```
98102

99103
Unsubscribe a previously subscribe value.
@@ -102,6 +106,8 @@ Arguments:
102106

103107
- `key` (Buffer): a key representing a unique identifier of the object to publish.
104108

109+
Returns `Promise<void>`
110+
105111
## Contribute
106112

107113
Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/js-ipns/issues)!

Diff for: package.json

+10-9
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,23 @@
3232
},
3333
"homepage": "https://github.com/ipfs/js-datastore-pubsub#readme",
3434
"dependencies": {
35-
"assert": "^1.4.1",
36-
"async": "^2.6.2",
3735
"debug": "^4.1.1",
38-
"err-code": "^1.1.2",
39-
"interface-datastore": "~0.6.0",
36+
"err-code": "^2.0.0",
37+
"interface-datastore": "~0.7.0",
4038
"multibase": "~0.6.0"
4139
},
4240
"devDependencies": {
43-
"aegir": "^18.1.1",
41+
"aegir": "^20.0.0",
4442
"chai": "^4.2.0",
43+
"delay": "^4.3.0",
4544
"detect-node": "^2.0.4",
4645
"dirty-chai": "^2.0.1",
47-
"ipfs": "~0.34.4",
48-
"ipfsd-ctl": "~0.42.0",
49-
"libp2p-record": "~0.6.2",
50-
"sinon": "^7.2.4"
46+
"ipfs": "~0.37.0",
47+
"ipfs-http-client": "^33.0.0",
48+
"ipfsd-ctl": "^0.47.2",
49+
"libp2p-record": "~0.7.0",
50+
"promisify-es6": "^1.0.3",
51+
"sinon": "^7.4.1"
5152
},
5253
"contributors": [
5354
"Vasco Santos <vasco.santos@ua.pt>",

0 commit comments

Comments
 (0)