Comparing version 2.3.0 to 2.4.0
@@ -0,1 +1,8 @@ | ||
### 2.4.0 | ||
* Experimental support for [vert.x 2.x](http://vertx.io). Should now run in vert.x >= 1.1.0. | ||
* New `when.isPromiseLike` as the more accurately-named synonym for `when.isPromise`. | ||
* **DEPRECATED**: `when.isPromise`. It can only tell you that something is "promise-like" (aka "thenable") anyway. Use the new, more accurately-named `when.isPromiseLike` instead. | ||
* Fix for promise monitor reporting extra unhandled rejections for `when.all` and `when.map`. | ||
### 2.3.0 | ||
@@ -2,0 +9,0 @@ |
14
delay.js
@@ -14,10 +14,14 @@ /** @license MIT License (c) copyright 2011-2013 original author or authors */ | ||
define(function(require) { | ||
/*global vertx,setTimeout*/ | ||
var when, setTimer; | ||
/*global setTimeout*/ | ||
var when, setTimer, cjsRequire, vertxSetTimer; | ||
when = require('./when'); | ||
cjsRequire = require; | ||
setTimer = typeof vertx === 'object' | ||
? function (f, ms) { return vertx.setTimer(ms, f); } | ||
: setTimeout; | ||
try { | ||
vertxSetTimer = cjsRequire('vertx').setTimer; | ||
setTimer = function (f, ms) { return vertxSetTimer(ms, f); }; | ||
} catch(e) { | ||
setTimer = setTimeout; | ||
} | ||
@@ -24,0 +28,0 @@ /** |
{ | ||
"name": "when", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "A lightweight Promises/A+ and when() implementation, plus other async goodies.", | ||
@@ -5,0 +5,0 @@ "keywords": ["Promises/A+", "promises-aplus", "promise", "promises", "deferred", "deferreds", "when", "async", "asynchronous", "cujo"], |
@@ -18,2 +18,9 @@ <a href="http://promises-aplus.github.com/promises-spec"><img src="http://promises-aplus.github.com/promises-spec/assets/logo-small.png" alt="Promises/A+ logo" align="right" /></a> | ||
### 2.4.0 | ||
* Experimental support for [vert.x 2.x](http://vertx.io). Should now run in vert.x >= 1.1.0. | ||
* New `when.isPromiseLike` as the more accurately-named synonym for `when.isPromise`. | ||
* **DEPRECATED**: `when.isPromise`. It can only tell you that something is "promise-like" (aka "thenable") anyway. Use the new, more accurately-named `when.isPromiseLike` instead. | ||
* Fix for promise monitor reporting extra unhandled rejections for `when.all` and `when.map`. | ||
### 2.3.0 | ||
@@ -20,0 +27,0 @@ |
@@ -15,11 +15,13 @@ /** @license MIT License (c) copyright 2011-2013 original author or authors */ | ||
define(function(require) { | ||
/*global vertx,setTimeout,clearTimeout*/ | ||
var when, setTimer, cancelTimer; | ||
/*global setTimeout,clearTimeout*/ | ||
var when, setTimer, cancelTimer, cjsRequire, vertx; | ||
when = require('./when'); | ||
cjsRequire = require; | ||
if(typeof vertx === 'object') { | ||
try { | ||
vertx = cjsRequire('vertx'); | ||
setTimer = function (f, ms) { return vertx.setTimer(ms, f); }; | ||
cancelTimer = vertx.cancelTimer; | ||
} else { | ||
} catch (e) { | ||
setTimer = setTimeout; | ||
@@ -26,0 +28,0 @@ cancelTimer = clearTimeout; |
100
when.js
@@ -12,6 +12,6 @@ /** @license MIT License (c) copyright 2011-2013 original author or authors */ | ||
* @author John Hann | ||
* @version 2.3.0 | ||
* @version 2.4.0 | ||
*/ | ||
(function(define, global) { 'use strict'; | ||
define(function () { | ||
define(function (require) { | ||
@@ -35,3 +35,4 @@ // Public API | ||
when.isPromise = isPromise; // Determine if a thing is a promise | ||
when.isPromise = isPromiseLike; // DEPRECATED: use isPromiseLike | ||
when.isPromiseLike = isPromiseLike; // Is something promise-like, aka thenable | ||
@@ -75,2 +76,21 @@ /** | ||
/** | ||
* Register handlers for this promise. | ||
* @param [onFulfilled] {Function} fulfillment handler | ||
* @param [onRejected] {Function} rejection handler | ||
* @param [onProgress] {Function} progress handler | ||
* @return {Promise} new Promise | ||
*/ | ||
then: function(onFulfilled, onRejected, onProgress) { | ||
/*jshint unused:false*/ | ||
var args, sendMessage; | ||
args = arguments; | ||
sendMessage = this._message; | ||
return _promise(function(resolve, reject, notify) { | ||
sendMessage('when', args, resolve, notify); | ||
}, this._status && this._status.observed()); | ||
}, | ||
/** | ||
* Register a rejection handler. Shortcut for .then(undefined, onRejected) | ||
@@ -257,3 +277,3 @@ * @param {function?} onRejected | ||
self = new Promise(_message, inspect); | ||
self.then = then; | ||
self._status = status; | ||
@@ -270,2 +290,11 @@ // Call the provider resolver to seal the promise's fate | ||
/** | ||
* Private message delivery. Queues and delivers messages to | ||
* the promise's ultimate fulfillment value or rejection reason. | ||
* @private | ||
* @param {String} type | ||
* @param {Array} args | ||
* @param {Function} resolve | ||
* @param {Function} notify | ||
*/ | ||
function _message(type, args, resolve, notify) { | ||
@@ -291,17 +320,2 @@ consumers ? consumers.push(deliver) : enqueue(function() { deliver(value); }); | ||
/** | ||
* Register handlers for this promise. | ||
* @param [onFulfilled] {Function} fulfillment handler | ||
* @param [onRejected] {Function} rejection handler | ||
* @param [onProgress] {Function} progress handler | ||
* @return {Promise} new Promise | ||
*/ | ||
function then(onFulfilled, onRejected, onProgress) { | ||
/*jshint unused:false*/ | ||
var args = arguments; | ||
return _promise(function(resolve, reject, notify) { | ||
_message('when', args, resolve, notify); | ||
}, status && status.observed()); | ||
} | ||
/** | ||
* Transition from pre-resolution state to post-resolution state, notifying | ||
@@ -379,3 +393,3 @@ * all listeners of the ultimate fulfillment or rejection | ||
function near(proxy, inspect) { | ||
return new Promise(function(type, args, resolve) { | ||
return new Promise(function (type, args, resolve) { | ||
try { | ||
@@ -418,3 +432,3 @@ resolve(proxy[type].apply(proxy, args)); | ||
function coerce(x) { | ||
if(x instanceof Promise) { | ||
if (x instanceof Promise) { | ||
return x; | ||
@@ -464,3 +478,3 @@ } | ||
* Proxy for a near rejection | ||
* @param {*} value | ||
* @param {*} reason | ||
* @constructor | ||
@@ -497,16 +511,18 @@ */ | ||
function updateStatus(value, status) { | ||
value._message('when', [ | ||
function () { status.fulfilled(); }, | ||
function (r) { status.rejected(r); } | ||
], identity, identity); | ||
value.then(statusFulfilled, statusRejected); | ||
function statusFulfilled() { status.fulfilled(); } | ||
function statusRejected(r) { status.rejected(r); } | ||
} | ||
/** | ||
* Determines if promiseOrValue is a promise or not | ||
* | ||
* @param {*} promiseOrValue anything | ||
* @returns {boolean} true if promiseOrValue is a {@link Promise} | ||
* Determines if x is promise-like, i.e. a thenable object | ||
* NOTE: Will return true for *any thenable object*, and isn't truly | ||
* safe, since it may attempt to access the `then` property of x (i.e. | ||
* clever/malicious getters may do weird things) | ||
* @param {*} x anything | ||
* @returns {boolean} true if x is promise-like | ||
*/ | ||
function isPromise(promiseOrValue) { | ||
return promiseOrValue && typeof promiseOrValue.then === 'function'; | ||
function isPromiseLike(x) { | ||
return x && typeof x.then === 'function'; | ||
} | ||
@@ -671,3 +687,3 @@ | ||
return promise(resolveMap); | ||
return _promise(resolveMap); | ||
@@ -781,4 +797,7 @@ function resolveMap(resolve, reject, notify) { | ||
var reduceArray, slice, fcall, nextTick, handlerQueue, | ||
setTimeout, funcProto, call, arrayProto, monitorApi, undef; | ||
setTimeout, funcProto, call, arrayProto, monitorApi, | ||
cjsRequire, undef; | ||
cjsRequire = require; | ||
// | ||
@@ -828,3 +847,3 @@ // Shared handler queue processing | ||
// vertx and finally setTimeout | ||
/*global setImmediate,MessageChannel,process,vertx*/ | ||
/*global setImmediate,MessageChannel,process*/ | ||
if (typeof setImmediate === 'function') { | ||
@@ -838,6 +857,9 @@ nextTick = setImmediate.bind(global); | ||
nextTick = process.nextTick; | ||
} else if (typeof vertx === 'object') { | ||
nextTick = vertx.runOnLoop; | ||
} else { | ||
nextTick = function(t) { setTimeout(t, 0); }; | ||
try { | ||
// vert.x 1.x || 2.x | ||
nextTick = cjsRequire('vertx').runOnLoop || cjsRequire('vertx').runOnContext; | ||
} catch(ignore) { | ||
nextTick = function(t) { setTimeout(t, 0); }; | ||
} | ||
} | ||
@@ -914,2 +936,2 @@ | ||
}); | ||
})(typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(); }, this); | ||
})(typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); }, this); |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
126460
3194
149
3