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

Commit a532b20

Browse files
committed
made all on events of providers handlers and not error first callbacks
1 parent b1f867d commit a532b20

File tree

7 files changed

+257
-146
lines changed

7 files changed

+257
-146
lines changed

dist/web3.js

Lines changed: 239 additions & 117 deletions
Large diffs are not rendered by default.

dist/web3.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,18 @@ RequestManager.prototype.setProvider = function (p, net) {
9595

9696
// listen to incoming notifications
9797
if(this.provider && this.provider.on) {
98-
this.provider.on('data', function requestManagerNotification(err, result){
99-
if(!err) {
100-
if(_this.subscriptions[result.params.subscription] && _this.subscriptions[result.params.subscription].callback)
101-
_this.subscriptions[result.params.subscription].callback(null, result.params.result);
102-
} else {
103-
104-
Object.keys(_this.subscriptions).forEach(function(id){
105-
if(_this.subscriptions[id].callback)
106-
_this.subscriptions[id].callback(err);
107-
});
98+
this.provider.on('data', function requestManagerNotification(result){
99+
if(_this.subscriptions[result.params.subscription] && _this.subscriptions[result.params.subscription].callback) {
100+
_this.subscriptions[result.params.subscription].callback(null, result.params.result);
108101
}
109102
});
103+
// TODO add error, end, timeout, connect??
104+
// this.provider.on('error', function requestManagerNotification(result){
105+
// Object.keys(_this.subscriptions).forEach(function(id){
106+
// if(_this.subscriptions[id].callback)
107+
// _this.subscriptions[id].callback(err);
108+
// });
109+
// }
110110
}
111111
};
112112

packages/web3-core-subscriptions/src/subscription.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@ Subscription.prototype.subscribe = function() {
276276
if(_this.options.requestManager.provider.once) {
277277
_this._reconnectIntervalId = setInterval(function () {
278278
// TODO check if that makes sense!
279-
_this.options.requestManager.provider.reconnect();
279+
if (_this.options.requestManager.provider.reconnect) {
280+
_this.options.requestManager.provider.reconnect();
281+
}
280282
}, 500);
281283

282284
_this.options.requestManager.provider.once('connect', function () {

packages/web3-providers-ipc/src/index.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var IpcProvider = function IpcProvider(path, net) {
5757
if(!id && result.method.indexOf('_subscription') !== -1) {
5858
_this.notificationCallbacks.forEach(function(callback){
5959
if(_.isFunction(callback))
60-
callback(null, result);
60+
callback(result);
6161
});
6262

6363
// fire the callback
@@ -95,12 +95,6 @@ IpcProvider.prototype.addDefaultEvents = function(){
9595

9696
this.connection.on('end', function(){
9797
_this._timeout();
98-
99-
// inform notifications
100-
_this.notificationCallbacks.forEach(function (callback) {
101-
if (_.isFunction(callback))
102-
callback(new Error('IPC socket connection closed'));
103-
});
10498
});
10599

106100
this.connection.on('timeout', function(){
@@ -231,6 +225,7 @@ IpcProvider.prototype.on = function (type, callback) {
231225
this.notificationCallbacks.push(callback);
232226
break;
233227

228+
// adds error, end, timeout, connect
234229
default:
235230
this.connection.on(type, callback);
236231
break;

packages/web3-providers-ws/src/index.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ var WebsocketProvider = function WebsocketProvider(url) {
6868
if(!id && result.method.indexOf('_subscription') !== -1) {
6969
_this.notificationCallbacks.forEach(function(callback){
7070
if(_.isFunction(callback))
71-
callback(null, result);
71+
callback(result);
7272
});
7373

7474
// fire the callback
@@ -95,16 +95,8 @@ WebsocketProvider.prototype.addDefaultEvents = function(){
9595
this.connection.onclose = function(e){
9696
_this._timeout();
9797

98-
var noteCb = _this.notificationCallbacks;
99-
10098
// reset all requests and callbacks
10199
_this.reset();
102-
103-
// cancel subscriptions
104-
noteCb.forEach(function (callback) {
105-
if (_.isFunction(callback))
106-
callback(e);
107-
});
108100
};
109101

110102
// this.connection.on('timeout', function(){

test/helpers/FakeIpcProvider.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ FakeIpcProvider.prototype.injectNotification = function (notification) {
9696
setTimeout(function(){
9797
_this.notificationCallbacks.forEach(function(cb){
9898
if(notification && cb)
99-
cb(null, notification);
99+
cb(notification);
100100
});
101101
}, 100 + this.notificationCount);
102102

0 commit comments

Comments
 (0)