Skip to content

Commit 974a6dc

Browse files
committed
Improved retry.
1 parent 0b6ac3a commit 974a6dc

File tree

7 files changed

+37
-35
lines changed

7 files changed

+37
-35
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"author": "Ma Bingyao <[email protected]>",
33
"name": "hprose-html5",
4-
"version": "2.0.21",
4+
"version": "2.0.22",
55
"description": "Hprose is a High Performance Remote Object Service Engine.",
66
"keywords": [
77
"hprose",

dist/hprose-html5.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/hprose-html5.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.

dist/hprose-html5.src.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Hprose for HTML5 v2.0.21
1+
// Hprose for HTML5 v2.0.22
22
// Copyright (c) 2008-2016 http://hprose.com
33
// Hprose is freely distributable under the MIT license.
44
// For all details and documentation:
@@ -3902,7 +3902,7 @@
39023902
* *
39033903
* hprose client for HTML5. *
39043904
* *
3905-
* LastModified: Oct 12, 2016 *
3905+
* LastModified: Nov 14, 2016 *
39063906
* Author: Ma Bingyao <[email protected]> *
39073907
* *
39083908
\**********************************************************/
@@ -3991,15 +3991,17 @@
39913991
}
39923992

39933993
function afterFilterHandler(request, context) {
3994-
return self.sendAndReceive(request, context);
3994+
return self.sendAndReceive(request, context).catchError(function(e) {
3995+
var response = retry(request, context);
3996+
if (response !== null) {
3997+
return response;
3998+
}
3999+
throw e;
4000+
});
39954001
}
39964002

39974003
function sendAndReceive(request, context, onsuccess, onerror) {
3998-
_beforeFilterHandler(request, context)
3999-
.then(onsuccess, function(e) {
4000-
if (retry(request, context, onsuccess, onerror)) { return; }
4001-
onerror(e);
4002-
});
4004+
_beforeFilterHandler(request, context).then(onsuccess, onerror);
40034005
}
40044006

40054007
function failswitch() {
@@ -4019,7 +4021,7 @@
40194021
_onfailswitch(self);
40204022
}
40214023

4022-
function retry(data, context, onsuccess, onerror) {
4024+
function retry(data, context) {
40234025
if (context.failswitch) {
40244026
failswitch();
40254027
}
@@ -4032,16 +4034,15 @@
40324034
interval = 5000;
40334035
}
40344036
if (interval > 0) {
4035-
global.setTimeout(function() {
4036-
sendAndReceive(data, context, onsuccess, onerror);
4037-
}, interval);
4037+
return Future.delayed(interval, function() {
4038+
return afterFilterHandler(data, context);
4039+
});
40384040
}
40394041
else {
4040-
sendAndReceive(data, context, onsuccess, onerror);
4042+
return afterFilterHandler(data, context);
40414043
}
4042-
return true;
40434044
}
4044-
return false;
4045+
return null;
40454046
}
40464047

40474048
function initService(stub) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "hprose-html5",
33
"filename": "hprose-html5.js",
4-
"version": "2.0.21",
4+
"version": "2.0.22",
55
"description": "Hprose is a High Performance Remote Object Service Engine.",
66
"homepage": "https://github.com/andot/hprose",
77
"keywords": [

src/Client.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* *
1313
* hprose client for HTML5. *
1414
* *
15-
* LastModified: Oct 12, 2016 *
15+
* LastModified: Nov 14, 2016 *
1616
* Author: Ma Bingyao <[email protected]> *
1717
* *
1818
\**********************************************************/
@@ -101,15 +101,17 @@
101101
}
102102

103103
function afterFilterHandler(request, context) {
104-
return self.sendAndReceive(request, context);
104+
return self.sendAndReceive(request, context).catchError(function(e) {
105+
var response = retry(request, context);
106+
if (response !== null) {
107+
return response;
108+
}
109+
throw e;
110+
});
105111
}
106112

107113
function sendAndReceive(request, context, onsuccess, onerror) {
108-
_beforeFilterHandler(request, context)
109-
.then(onsuccess, function(e) {
110-
if (retry(request, context, onsuccess, onerror)) { return; }
111-
onerror(e);
112-
});
114+
_beforeFilterHandler(request, context).then(onsuccess, onerror);
113115
}
114116

115117
function failswitch() {
@@ -129,7 +131,7 @@
129131
_onfailswitch(self);
130132
}
131133

132-
function retry(data, context, onsuccess, onerror) {
134+
function retry(data, context) {
133135
if (context.failswitch) {
134136
failswitch();
135137
}
@@ -142,16 +144,15 @@
142144
interval = 5000;
143145
}
144146
if (interval > 0) {
145-
global.setTimeout(function() {
146-
sendAndReceive(data, context, onsuccess, onerror);
147-
}, interval);
147+
return Future.delayed(interval, function() {
148+
return afterFilterHandler(data, context);
149+
});
148150
}
149151
else {
150-
sendAndReceive(data, context, onsuccess, onerror);
152+
return afterFilterHandler(data, context);
151153
}
152-
return true;
153154
}
154-
return false;
155+
return null;
155156
}
156157

157158
function initService(stub) {

src/CopyRight.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Hprose for HTML5 v2.0.21
1+
// Hprose for HTML5 v2.0.22
22
// Copyright (c) 2008-2016 http://hprose.com
33
// Hprose is freely distributable under the MIT license.
44
// For all details and documentation:

0 commit comments

Comments
 (0)