Skip to content

Commit 36e96f8

Browse files
author
RyLee Harrison
committed
correction: Promise logic
1 parent 8a0bb2d commit 36e96f8

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

index.js

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,40 @@ class AsyncClient {
1717
return this._client.handleMessage;
1818
}
1919

20-
async publish (...args) {
21-
return this._client.publish(...args);
22-
}
23-
24-
async subscribe (...args) {
25-
return this._client.subscribe(...args)
26-
}
27-
28-
async unsubscribe (...args) {
29-
return this._client.unsubscribe(...args);
30-
}
31-
32-
async end (...args) {
33-
return this._client.end(...args);
20+
publish (...args) {
21+
return new Promise((resolve, reject) => {
22+
this._client.publish(...args, (err, result) => {
23+
if (err) reject(err)
24+
else resolve(result)
25+
})
26+
})
27+
}
28+
29+
subscribe (...args) {
30+
return new Promise((resolve, reject) => {
31+
this._client.subscribe(...args, (err, result) => {
32+
if (err) reject(err)
33+
else resolve(result)
34+
})
35+
})
36+
}
37+
38+
unsubscribe (...args) {
39+
return new Promise((resolve, reject) => {
40+
this._client.unsubscribe(...args, (err, result) => {
41+
if (err) reject(err)
42+
else resolve(result)
43+
})
44+
})
45+
}
46+
47+
end (...args) {
48+
return new Promise((resolve, reject) => {
49+
this._client.end(...args, (err, result) => {
50+
if (err) reject(err)
51+
else resolve(result)
52+
})
53+
})
3454
}
3555

3656
addListener (...args) {

0 commit comments

Comments
 (0)