From 4b48b80911a6a1d3da10e8b5c86a512086fbcada Mon Sep 17 00:00:00 2001 From: "s.vychegzhanin" Date: Tue, 12 Jan 2016 16:52:36 +0500 Subject: [PATCH 1/2] defer reject fix --- dist/prow.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/prow.js b/dist/prow.js index b374c42..09877ca 100644 --- a/dist/prow.js +++ b/dist/prow.js @@ -35,13 +35,13 @@ if (timelimit) { timeoutReject = setTimeout(reject.bind(this, "PROW TIMEOUT"), timelimit); } - defer.resolve = function() { + defer.resolve = function(result) { clearTimeout(timeoutResolve); resolve.apply(this, arguments); }; - defer.reject = function() { + defer.reject = function(reason) { clearTimeout(timeoutReject); - reject.apply(this); + reject.apply(this, arguments); }; }); return defer; diff --git a/package.json b/package.json index f85ef8c..6d49e39 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "prow", - "version": "0.2.1", + "version": "0.2.2", "description": "JS Promises Flow Lib", "main": "dist/prow.js", "scripts": { From 1cfcf9bf2df2e3bf63540bc85e81914b6c631914 Mon Sep 17 00:00:00 2001 From: "s.vychegzhanin" Date: Tue, 12 Jan 2016 16:54:03 +0500 Subject: [PATCH 2/2] defer reject fix --- dist/prow.min.js | 2 +- src/prow.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/prow.min.js b/dist/prow.min.js index bf801be..d8227e3 100644 --- a/dist/prow.min.js +++ b/dist/prow.min.js @@ -1 +1 @@ -!function(){var a={};a.when=function(b){var c;return b instanceof Promise&&"function"==typeof b.then?b instanceof Promise?b:(c=a.defer(),b.then(function(){c.resolve.apply(this,arguments)},function(){c.reject.apply(this,arguments)}),c.promise):Promise.resolve(b)},a.nextTick=function(a){process&&process.nextTick?process.nextTick(a):setTimeout(a,0)},a.defer=function(a,b){var c,d,e={};return e.promise=new Promise(function(f,g){a&&(c=setTimeout(f,a)),b&&(d=setTimeout(g.bind(this,"PROW TIMEOUT"),b)),e.resolve=function(){clearTimeout(c),f.apply(this,arguments)},e.reject=function(){clearTimeout(d),g.apply(this)}}),e},a.delay=function(a,b){var c=new Promise(function(c,d){setTimeout(function(){c(b)},a)});return c},a.limit=function(a,b){var c=new Promise(function(c,d){setTimeout(function(){d(b)},a)});return c},a.waterfall=function(b){var c=b.length,d=a.defer();try{var e=function(f,g){if(f>=c)d.resolve(g);else{var h=b[f];a.when(h.call(null,g)).then(function(a){e(++f,a)},function(a){d.reject(a)})["catch"](function(a){d.reject(a)})}};e(0)}catch(f){d.reject(f)}return d.promise},a.parallel=function(b,c,d){var e=b.length,f=a.defer();c=Math.min(c||e,e);var g=0,h=0,i=function(){if(h>=e)return void(0===g&&f.resolve());var d=b[h++];g++,a.when(d.call()).then(function(){g--,i()},function(){g--,i()})["catch"](function(){g--,i()}),c>g&&i()};return i(),d?{push:function(a){b&&(Array.isArray(a)?b=b.concat(a):b.push(a)),e=b.length},promise:f.promise}:f.promise},a.queue=function(b,c){return a.parallel.call(this,b,1,c)},a.retry=function(b,c,d){c=void 0===c?1:c;var e=a.defer(),f=function(b){0===c?e.reject(b):void 0!==d?a.delay(d).then(g.bind(this,--c)):g(--c)},g=function(c){a.when(b.call()).then(function(a){e.resolve(a)},f)["catch"](f)};return g(--c),e.promise},a.times=function(b,c){c=void 0===c?1:c;for(var d=[],e=a.defer(),f=0;c>f;f++)d.push(b);return a.queue(d).then(e.resolve.bind(e,d),e.resolve.bind(e,d)),e.promise},a.await=function(b,c,d){d=d||0;var e,f=!1,g=a.defer(null,d),h=function(){var a=b();a?g.resolve(a):f||(e=setTimeout(h,c))};return g.promise.then(null,function(){f=!0,clearTimeout(e)}),h(),g.promise},"object"==typeof module&&module.exports?module.exports=a:"function"==typeof define&&define.amd?define(function(){return a}):"object"==typeof window&&(window.prow=a)}(); \ No newline at end of file +!function(){var a={};a.when=function(b){var c;return b instanceof Promise&&"function"==typeof b.then?b instanceof Promise?b:(c=a.defer(),b.then(function(){c.resolve.apply(this,arguments)},function(){c.reject.apply(this,arguments)}),c.promise):Promise.resolve(b)},a.nextTick=function(a){process&&process.nextTick?process.nextTick(a):setTimeout(a,0)},a.defer=function(a,b){var c,d,e={};return e.promise=new Promise(function(f,g){a&&(c=setTimeout(f,a)),b&&(d=setTimeout(g.bind(this,"PROW TIMEOUT"),b)),e.resolve=function(a){clearTimeout(c),f.apply(this,arguments)},e.reject=function(a){clearTimeout(d),g.apply(this,arguments)}}),e},a.delay=function(a,b){var c=new Promise(function(c,d){setTimeout(function(){c(b)},a)});return c},a.limit=function(a,b){var c=new Promise(function(c,d){setTimeout(function(){d(b)},a)});return c},a.waterfall=function(b){var c=b.length,d=a.defer();try{var e=function(f,g){if(f>=c)d.resolve(g);else{var h=b[f];a.when(h.call(null,g)).then(function(a){e(++f,a)},function(a){d.reject(a)})["catch"](function(a){d.reject(a)})}};e(0)}catch(f){d.reject(f)}return d.promise},a.parallel=function(b,c,d){var e=b.length,f=a.defer();c=Math.min(c||e,e);var g=0,h=0,i=function(){if(h>=e)return void(0===g&&f.resolve());var d=b[h++];g++,a.when(d.call()).then(function(){g--,i()},function(){g--,i()})["catch"](function(){g--,i()}),c>g&&i()};return i(),d?{push:function(a){b&&(Array.isArray(a)?b=b.concat(a):b.push(a)),e=b.length},promise:f.promise}:f.promise},a.queue=function(b,c){return a.parallel.call(this,b,1,c)},a.retry=function(b,c,d){c=void 0===c?1:c;var e=a.defer(),f=function(b){0===c?e.reject(b):void 0!==d?a.delay(d).then(g.bind(this,--c)):g(--c)},g=function(c){a.when(b.call()).then(function(a){e.resolve(a)},f)["catch"](f)};return g(--c),e.promise},a.times=function(b,c){c=void 0===c?1:c;for(var d=[],e=a.defer(),f=0;c>f;f++)d.push(b);return a.queue(d).then(e.resolve.bind(e,d),e.resolve.bind(e,d)),e.promise},a.await=function(b,c,d){d=d||0;var e,f=!1,g=a.defer(null,d),h=function(){var a=b();a?g.resolve(a):f||(e=setTimeout(h,c))};return g.promise.then(null,function(){f=!0,clearTimeout(e)}),h(),g.promise},"object"==typeof module&&module.exports?module.exports=a:"function"==typeof define&&define.amd?define(function(){return a}):"object"==typeof window&&(window.prow=a)}(); \ No newline at end of file diff --git a/src/prow.js b/src/prow.js index 098b4dc..3c73174 100644 --- a/src/prow.js +++ b/src/prow.js @@ -51,14 +51,14 @@ timeoutReject = setTimeout(reject.bind(this, 'PROW TIMEOUT'), timelimit); } - defer.resolve = function () { + defer.resolve = function (result) { clearTimeout(timeoutResolve); resolve.apply(this, arguments); }; - defer.reject = function () { + defer.reject = function (reason) { clearTimeout(timeoutReject); - reject.apply(this); + reject.apply(this, arguments); }; });