Author: ygrego Date: 2015-03-26 16:00:11 +0000 (Thu, 26 Mar 2015) New Revision: 973 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/973 Log: This class permit create and manage a timer. Added: oipf/js/utils/Timeout.js Added: oipf/js/utils/Timeout.js =================================================================== --- oipf/js/utils/Timeout.js (rev 0) +++ oipf/js/utils/Timeout.js 2015-03-26 16:00:11 UTC (rev 973) @@ -0,0 +1,33 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +var Timeout = Class.extend({ + timerId: null, + + promise: null, + + init: function(time) { + var self = this; + this.promise = new Promise(function(resolve, reject) { + self.timerId = setTimeout(resolve, time); + }); + }, + + then: function(callback) { + this.promise.then(callback); + return this; + }, + + catch: function(callback) { + this.promise.catch(callback); + return this; + }, + + cancel: function() { + clearTimeout(this.timerId); + } + +}); +
participants (1)
-
ygregoï¼ users.nuiton.org