Comparing version 0.11.0 to 1.0.0
{ | ||
"name" : "ya-promise" | ||
, "version" : "0.11.0" | ||
, "version" : "1.0.0" | ||
, "description" : "Yet Another promise/A+ library" | ||
@@ -17,8 +17,11 @@ , "keywords" : ["defer", "deferred", "promise", "promise/A", "promise/A+" | ||
, "main" : "ya-promise.js" | ||
, "scripts" : { "test": "promises-aplus-tests test/adapter" | ||
, "scripts" : { "test": "promises-aplus-tests test/adapter && mocha -R spec test/??-*.js" | ||
, "prepublish": "uglifyjs ya-promise.js -o ya-promise.min.js -m" } | ||
, "dependencies": {} | ||
, "devDependencies": { "promises-aplus-tests" : ">=1.3.1" | ||
, "uglify-js": ">= 2.2.5" } | ||
, "uglify-js": ">= 2.2.5" | ||
, "lodash": ">= 1.2.0" | ||
, "mocha": ">= 1.9.0" | ||
, "vow": "*" } | ||
, "engines" : { "node" : ">=0.10.0" } | ||
} |
@@ -20,2 +20,3 @@ # Yet Another Promise/A+ Library | ||
5. speed. | ||
6. make it as Q-like as possible. | ||
@@ -191,2 +192,46 @@ The advatages of this library to you that other libraries may or may not have: | ||
### Timeout a Promise | ||
```javascript | ||
promise.timeout(ms).then(onFulfilled, onRejected) | ||
``` | ||
If `promise` is resolved or rejected in less than `ms` milliseconds then | ||
`onFulfilled` or `onRejected` (respectively) will be called with the `value` | ||
or `reason` given. | ||
If `promise` is not resolved or rejected within that time limit, then | ||
the `promise` will be rejected with the reason set to | ||
`"Timed out after " + ms + " ms"`. | ||
In node.js the `timeoutId` returned by `setTimeout` has a `unref` method that | ||
will prevent this timer from allowing the node.js event-loop to end. If | ||
`timeoutId` has a `unref` method, it is called. | ||
### Delay a Promise | ||
Q-alike: [`promise.delay()`][Qpromisedelay] | ||
```javascript | ||
delayed_promise = promise.delay(ms) | ||
``` | ||
From the time where `delayed_promise` is created a timer is started for `ms` | ||
milliseconds. If `promise` is fulfilled or rejected within that timer then | ||
`delayed_promise` will not be resolved/rejected till the timer expires. If | ||
the timer has already expired `delayed_promise` will be resolved/rejected | ||
immediately. `delayed_promise` will always be resolved/rejected with the same | ||
value/reason `promise` was. | ||
### Create a Promise whos Resolution is delayed | ||
Q-alike: [`Q.delay()`][Qdelay] | ||
```javascript | ||
delayed = Y.delay(ms) | ||
``` | ||
This is a promise-like version of `setTimeout()` but looks nicer. | ||
```javascript | ||
Y.delay(1000).then(doSomthing) | ||
``` | ||
### Create a Fulfilled or Rejected Promise | ||
@@ -564,1 +609,3 @@ Q-alike: [`Q.reject()`][Qreject] | ||
[Qdenodeify]: https://github.com/kriskowal/q/wiki/API-Reference#qdenodeifynodefunc-args | ||
[Qpromisedelay]: https://github.com/kriskowal/q/wiki/API-Reference#promisedelayms | ||
[Qdelay]: https://github.com/kriskowal/q/wiki/API-Reference#qdelayms |
@@ -121,6 +121,8 @@ | ||
, promise = new Promise(then, spread) | ||
, deferred = { promise: promise | ||
, resolve: resolve | ||
, reject : reject } | ||
, deferred = this | ||
this.promise = promise | ||
this.resolve = resolve | ||
this.reject = reject | ||
function then(onFulfilled, onRejected){ | ||
@@ -176,3 +178,2 @@ var d = new Deferred() | ||
return deferred | ||
} //Deferred() | ||
@@ -201,8 +202,25 @@ | ||
Promise.prototype.delay = function(ms){ | ||
var self = this | ||
, d = Y.defer() | ||
var d = Y.defer() | ||
, p = d.promise | ||
, t0 = Date.now() | ||
setTimeout(function(){ d.resolve(self) }, ms) | ||
setTimeout(function(){ }, ms) | ||
return d.promise | ||
this.then( | ||
function(v){ | ||
var sofar = Date.now() - t0 | ||
if ( ms - sofar > 0 ) | ||
setTimeout(function(){ d.resolve(v) }, ms - sofar) | ||
else | ||
d.resolve(v) | ||
} | ||
, function(r){ | ||
var sofar = Date.now() - t0 | ||
if ( ms - sofar > 0 ) | ||
setTimeout(function(){ d.reject(r) }, ms - sofar) | ||
else | ||
d.reject(r) | ||
}) | ||
return p | ||
} | ||
@@ -209,0 +227,0 @@ |
@@ -1,1 +0,1 @@ | ||
(function(e){if(typeof bootstrap==="function"){bootstrap("promise",e)}else if(typeof exports==="object"){module.exports=e()}else if(typeof define==="function"&&define.amd){define(e)}else if(typeof ses!=="undefined"){if(!ses.ok()){return}else{ses.makeY=e}}else{Y=e()}})(function(){"use strict";function e(n){return e.when(n)}e.defer=function(){return new i};e.deferred=e.defer;e.resolved=function(e){var n=new i;n.resolve(e);return n.promise};e.rejected=function(e){var n=new i;n.reject(e);return n.promise};e.when=function(e){if(n(e))return e;var r=new i;if(e&&typeof e.then==="function")e.then(function(e){r.resolve(e)},function(e){r.reject(e)});else r.resolve(e);return r.promise};e.all=function(n){var r=0,t=e.defer(),i=[];n.forEach(function(n,o){r+=1;e.when(n).then(function(e){r-=1;i[o]=e;if(r===0)t.resolve(i)},function(e){t.reject(e)})});return t.promise};e.delay=function(n){return e.resolved().delay(n)};e.promisify=l;e.nfbind=l;e.denodeify=l;e.isPromise=function(e){return e instanceof o};e.isDeferred=function(e){return e instanceof i};var n=e.isPromise,r=e.isDeferred;var t;Object.defineProperty(e,"nextTick",{get:function(){return t},set:function(e){t=e;return e},configurable:true,enumerable:true});if(typeof setImmediate==="function"){if(typeof window!=="undefined")e.nextTick=setImmediate.bind(window);else e.nextTick=setImmediate}else if(typeof process!=="undefined"&&process.nextTick)e.nextTick=process.nextTick;else e.nextTick=function(e){setTimeout(e,0)};function i(){var e=[],n=new o(t,l),r={promise:n,resolve:d,reject:a};function t(n,r){var t=new i;e.push({deferred:t,fulfilled:n,rejected:r,spread:false});return t.promise}function l(n,r){var t=new i;e.push({deferred:t,fulfilled:n,rejected:r,spread:true});return t.promise}function d(t){for(var i=0;i<e.length;i++){if(typeof e[i].fulfilled!=="function")e[i].deferred.resolve(t);else c(e[i].fulfilled,t,e[i].deferred,e[i].spread)}r.reject=r.resolve=s;n.then=f(n,t,false);n.spread=f(n,t,true)}function a(t){for(var i=0;i<e.length;i++){if(typeof e[i].rejected!=="function")e[i].deferred.reject(t);else c(e[i].rejected,t,e[i].deferred,false)}r.reject=r.resolve=s;n.then=u(n,t);n.spread=u(n,t)}return r}function o(e,n){this.then=e;this.spread=n}o.prototype.timeout=function(n){var r=e.defer(),t=setTimeout(function(){r.reject("Timed out after "+n+" ms")},n);if(typeof t.unref==="function")t.unref();this.then(function(e){clearTimeout(t);r.resolve(e)},function(e){clearTimeout(t);r.reject(e)});return r.promise};o.prototype.delay=function(n){var r=this,t=e.defer();setTimeout(function(){t.resolve(r)},n);return t.promise};function f(e,n,r){r=r||false;return function t(t,o){var f;if(typeof t!=="function")return e;c(t,n,f=new i,r);return f.promise}}function u(e,n){return function r(r,t){var o;if(typeof t!=="function")return e;c(t,n,o=new i,false);return o.promise}}function s(){}function c(e,n,r,i){t(function(){var t;try{if(i&&Array.isArray(n))t=e.apply(void 0,n);else t=e(n);if(t&&typeof t.then=="function")t.then(function(e){r.resolve(e)},function(e){r.reject(e)});else r.resolve(t)}catch(o){r.reject(o)}})}function l(n,r){return function(){var t=Array.prototype.slice.call(arguments),i=e.defer();t.push(function(e){if(e){i.reject(e);return}if(arguments.length>2)i.resolve(Array.prototype.slice.call(arguments,1));else i.resolve(arguments[1])});n.apply(r,t);return i.promise}}return e}); | ||
(function(e){if(typeof bootstrap==="function"){bootstrap("promise",e)}else if(typeof exports==="object"){module.exports=e()}else if(typeof define==="function"&&define.amd){define(e)}else if(typeof ses!=="undefined"){if(!ses.ok()){return}else{ses.makeY=e}}else{Y=e()}})(function(){"use strict";function e(n){return e.when(n)}e.defer=function(){return new i};e.deferred=e.defer;e.resolved=function(e){var n=new i;n.resolve(e);return n.promise};e.rejected=function(e){var n=new i;n.reject(e);return n.promise};e.when=function(e){if(n(e))return e;var t=new i;if(e&&typeof e.then==="function")e.then(function(e){t.resolve(e)},function(e){t.reject(e)});else t.resolve(e);return t.promise};e.all=function(n){var t=0,r=e.defer(),i=[];n.forEach(function(n,o){t+=1;e.when(n).then(function(e){t-=1;i[o]=e;if(t===0)r.resolve(i)},function(e){r.reject(e)})});return r.promise};e.delay=function(n){return e.resolved().delay(n)};e.promisify=l;e.nfbind=l;e.denodeify=l;e.isPromise=function(e){return e instanceof o};e.isDeferred=function(e){return e instanceof i};var n=e.isPromise,t=e.isDeferred;var r;Object.defineProperty(e,"nextTick",{get:function(){return r},set:function(e){r=e;return e},configurable:true,enumerable:true});if(typeof setImmediate==="function"){if(typeof window!=="undefined")e.nextTick=setImmediate.bind(window);else e.nextTick=setImmediate}else if(typeof process!=="undefined"&&process.nextTick)e.nextTick=process.nextTick;else e.nextTick=function(e){setTimeout(e,0)};function i(){var e=[],n=new o(r,l),t=this;this.promise=n;this.resolve=a;this.reject=d;function r(n,t){var r=new i;e.push({deferred:r,fulfilled:n,rejected:t,spread:false});return r.promise}function l(n,t){var r=new i;e.push({deferred:r,fulfilled:n,rejected:t,spread:true});return r.promise}function a(r){for(var i=0;i<e.length;i++){if(typeof e[i].fulfilled!=="function")e[i].deferred.resolve(r);else c(e[i].fulfilled,r,e[i].deferred,e[i].spread)}t.reject=t.resolve=s;n.then=f(n,r,false);n.spread=f(n,r,true)}function d(r){for(var i=0;i<e.length;i++){if(typeof e[i].rejected!=="function")e[i].deferred.reject(r);else c(e[i].rejected,r,e[i].deferred,false)}t.reject=t.resolve=s;n.then=u(n,r);n.spread=u(n,r)}}function o(e,n){this.then=e;this.spread=n}o.prototype.timeout=function(n){var t=e.defer(),r=setTimeout(function(){t.reject("Timed out after "+n+" ms")},n);if(typeof r.unref==="function")r.unref();this.then(function(e){clearTimeout(r);t.resolve(e)},function(e){clearTimeout(r);t.reject(e)});return t.promise};o.prototype.delay=function(n){var t=e.defer(),r=t.promise,i=Date.now();setTimeout(function(){},n);this.then(function(e){var r=Date.now()-i;if(n-r>0)setTimeout(function(){t.resolve(e)},n-r);else t.resolve(e)},function(e){var r=Date.now()-i;if(n-r>0)setTimeout(function(){t.reject(e)},n-r);else t.reject(e)});return r};function f(e,n,t){t=t||false;return function r(r,o){var f;if(typeof r!=="function")return e;c(r,n,f=new i,t);return f.promise}}function u(e,n){return function t(t,r){var o;if(typeof r!=="function")return e;c(r,n,o=new i,false);return o.promise}}function s(){}function c(e,n,t,i){r(function(){var r;try{if(i&&Array.isArray(n))r=e.apply(void 0,n);else r=e(n);if(r&&typeof r.then=="function")r.then(function(e){t.resolve(e)},function(e){t.reject(e)});else t.resolve(r)}catch(o){t.reject(o)}})}function l(n,t){return function(){var r=Array.prototype.slice.call(arguments),i=e.defer();r.push(function(e){if(e){i.reject(e);return}if(arguments.length>2)i.resolve(Array.prototype.slice.call(arguments,1));else i.resolve(arguments[1])});n.apply(t,r);return i.promise}}return e}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
36954
12
432
0
608
5