summaryrefslogtreecommitdiff
path: root/js/src/Ice/RetryQueue.js
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2016-08-19 21:25:18 +0200
committerJose <jose@zeroc.com>2016-08-19 21:25:18 +0200
commitc8d32e04873be7938915c606027c84c8ab832f6b (patch)
treef862751cfaddcf5bb7b82a7c04a299d471f948d4 /js/src/Ice/RetryQueue.js
parentFix ICE-7278 (diff)
downloadice-c8d32e04873be7938915c606027c84c8ab832f6b.tar.bz2
ice-c8d32e04873be7938915c606027c84c8ab832f6b.tar.xz
ice-c8d32e04873be7938915c606027c84c8ab832f6b.zip
ES6 mapping updates
Diffstat (limited to 'js/src/Ice/RetryQueue.js')
-rw-r--r--js/src/Ice/RetryQueue.js129
1 files changed, 67 insertions, 62 deletions
diff --git a/js/src/Ice/RetryQueue.js b/js/src/Ice/RetryQueue.js
index 5a4e5f61ca2..6e9af19492d 100644
--- a/js/src/Ice/RetryQueue.js
+++ b/js/src/Ice/RetryQueue.js
@@ -7,52 +7,93 @@
//
// **********************************************************************
-var Ice = require("../Ice/ModuleRegistry").Ice;
-Ice.__M.require(module, ["../Ice/Class", "../Ice/LocalException"]);
+const Ice = require("../Ice/LocalException").Ice;
-var Class = Ice.Class;
+class RetryTask
+{
+ constructor(instance, queue, outAsync, interval)
+ {
+ this._instance = instance;
+ this._queue = queue;
+ this._outAsync = outAsync;
+ }
+
+ run()
+ {
+ this._outAsync.__retry();
+ this._queue.remove(this);
+ }
+
+ destroy()
+ {
+ try
+ {
+ this._outAsync.__abort(new Ice.CommunicatorDestroyedException());
+ }
+ catch(ex)
+ {
+ // Abort shouldn't throw if there's no callback, ignore.
+ }
+ }
+
+ asyncRequestCanceled(outAsync, ex)
+ {
+ if(this._queue.cancel(this))
+ {
+ if(this._instance.traceLevels().retry >= 1)
+ {
+ this._instance.initializationData().logger.trace(this._instance.traceLevels().retryCat,
+ "operation retry canceled\n" + ex.toString());
+ }
+ this._outAsync.__completedEx(ex);
+ }
+ }
+}
-var RetryQueue = Class({
- __init__: function(instance)
+class RetryQueue
+{
+ constructor(instance)
{
this._instance = instance;
this._requests = [];
- },
- add: function(outAsync, interval)
+ }
+
+ add(outAsync, interval)
{
if(this._instance === null)
{
throw new Ice.CommunicatorDestroyedException();
}
- var task = new RetryTask(this._instance, this, outAsync);
+ let task = new RetryTask(this._instance, this, outAsync);
outAsync.__cancelable(task); // This will throw if the request is canceled
- task.token = this._instance.timer().schedule(function()
- {
- task.run();
- }, interval);
+ task.token = this._instance.timer().schedule(() => task.run(), interval);
this._requests.push(task);
- },
- destroy: function()
+ }
+
+ destroy()
{
- for(var i = 0; i < this._requests.length; ++i)
- {
- this._instance.timer().cancel(this._requests[i].token);
- this._requests[i].destroy();
- }
+ this._requests.forEach(request =>
+ {
+ this._instance.timer().cancel(request.token);
+ request.destroy();
+ });
+
this._requests = [];
this._instance = null;
- },
- remove: function(task)
+ }
+
+ remove(task)
{
- var idx = this._requests.indexOf(task);
+ const idx = this._requests.indexOf(task);
if(idx >= 0)
{
this._requests.splice(idx, 1);
}
- },
- cancel: function(task)
+ }
+
+ cancel(task)
{
- var idx = this._requests.indexOf(task);
+ const idx = this._requests.indexOf(task);
if(idx >= 0)
{
this._requests.splice(idx, 1);
@@ -60,43 +101,7 @@ var RetryQueue = Class({
}
return false;
}
-});
+}
Ice.RetryQueue = RetryQueue;
-var RetryTask = Class({
- __init__: function(instance, queue, outAsync, interval)
- {
- this._instance = instance;
- this._queue = queue;
- this._outAsync = outAsync;
- },
- run: function()
- {
- this._outAsync.__retry();
- this._queue.remove(this);
- },
- destroy: function()
- {
- try
- {
- this._outAsync.__abort(new Ice.CommunicatorDestroyedException());
- }
- catch(ex)
- {
- // Abort shouldn't throw if there's no callback, ignore.
- }
- },
- asyncRequestCanceled: function(outAsync, ex)
- {
- if(this._queue.cancel(this))
- {
- if(this._instance.traceLevels().retry >= 1)
- {
- this._instance.initializationData().logger.trace(this._instance.traceLevels().retryCat,
- "operation retry canceled\n" + ex.toString());
- }
- this._outAsync.__completedEx(ex);
- }
- }
-});
module.exports.Ice = Ice;