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

Commit 866cb99

Browse files
Merge pull request #3696 from ethereum/wyatt/3689-unsubscribe
Update clearSubscriptions to have return value
2 parents c57bd8c + 175703c commit 866cb99

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ npm-debug.log
1010
node_modules
1111
.idea/
1212
.npm/
13+
.history/
1314
.vscode/
1415
packages/web3/dist/
1516
lerna-debug.log

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,4 @@ Released with 1.0.0-beta.37 code base.
282282
### Fixed
283283

284284
- Fix parsing of non-`eth_subscription` provider events (#3660)
285+
- Fix return value for `clearSubscriptions` (#3689)

packages/web3-core-requestmanager/src/index.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -257,21 +257,29 @@ RequestManager.prototype.removeSubscription = function (id, callback) {
257257
* Should be called to reset the subscriptions
258258
*
259259
* @method reset
260+
*
261+
* @returns {boolean}
260262
*/
261263
RequestManager.prototype.clearSubscriptions = function (keepIsSyncing) {
262-
var _this = this;
264+
try {
265+
var _this = this;
266+
267+
// uninstall all subscriptions
268+
if (this.subscriptions.size > 0) {
269+
this.subscriptions.forEach(function (value, id) {
270+
if (!keepIsSyncing || value.name !== 'syncing')
271+
_this.removeSubscription(id);
272+
});
273+
}
263274

264-
// uninstall all subscriptions
265-
if (this.subscriptions.size > 0) {
266-
this.subscriptions.forEach(function (value, id) {
267-
if (!keepIsSyncing || value.name !== 'syncing')
268-
_this.removeSubscription(id);
269-
});
270-
}
275+
// reset notification callbacks etc.
276+
if(this.provider.reset)
277+
this.provider.reset();
271278

272-
// reset notification callbacks etc.
273-
if(this.provider.reset)
274-
this.provider.reset();
279+
return true
280+
} catch (e) {
281+
throw new Error(`Error while clearing subscriptions: ${e}`)
282+
}
275283
};
276284

277285
/**

test/eth.subscribe.ganache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('subscription connect/reconnect', function () {
5959
await waitSeconds(1); // Sub need a little time to set up
6060

6161
assert.equal(1, web3.eth._requestManager.subscriptions.size);
62-
web3.eth.clearSubscriptions();
62+
assert.ok(web3.eth.clearSubscriptions())
6363
assert.equal(0, web3.eth._requestManager.subscriptions.size);
6464
});
6565

0 commit comments

Comments
 (0)