Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

when

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

when - npm Package Compare versions

Comparing version 1.8.0 to 1.8.1

2

apply.js

@@ -15,3 +15,3 @@ /** @license MIT License (c) copyright B Cavalier & J Hann */

var toString = Object.prototype.toString;
/**

@@ -18,0 +18,0 @@ * Creates a function that accepts a function that takes individual

@@ -44,3 +44,3 @@ /** @license MIT License (c) copyright B Cavalier & J Hann */

// to the delegate
deferred.promise.then(delegate.resolve, delegate.reject, delegate.progress);
deferred.promise.then(delegate.resolve, delegate.reject, delegate.notify);

@@ -47,0 +47,0 @@ // Replace deferred's promise with the delegate promise

@@ -0,6 +1,16 @@

### 1.8.1
* Last 1.x.x release before 2.0.0 barring critical fixes.
* To prepare for 2.0.0, [test your code against the dev-200 branch](https://github.com/cujojs/when/tree/dev-200). It is fully API compatible, but has fully asynchronous resolutions.
* Performance improvements for [when/function](docs/api.md#synchronous-functions).
* [Documentation](docs/api.md) updates and fixes. Thanks, [@unscriptable](https://github.com/unscriptable)!
* **DEPRECATED:** `deferred.progress` and `deferred.resolver.progress`. Use [`deferred.notify`](docs/api.md#progress-events) and [`deferred.resolver.notify`](docs/api.md#progress-events) instead.
* **DEPRECATED:** [`when.chain`](docs/api.md#whenchain). Use [`resolver.resolve(promise)`](docs/api.md#resolver) or `resolver.resolve(promise.yield)` ([see `promise.yield`](docs/api.md#yield)) instead.
* **DEPRECATED:** `when/timed` module. Use [`when/delay`](docs/api.md#whendelay) and [`when/timeout`](docs/api.md#whentimeout) modules instead.
### 1.8.0
* New [when/function](docs/api.md#synchronous-functions), [when/node/function](docs/api.md#node-style-asynchronous-functions), and [when/callbacks](docs/api.md#asynchronous-functions) with functional programming goodness, and adapters for turning callback-based APIs into promise-based APIs. Kudos [@riccieri](https://github.com/riccieri)!
* New [when/unfold](api.md#whenunfold), and [when/unfold/list](api.md#whenunfoldlist) promise-aware anamorphic unfolds that can be used to generate and/or process unbounded lists.
* New [when/poll](api.md#whenpoll) promise-based periodic polling and task execution. Kudos [@scothis](https://github.com/scothis)!
* New [when/unfold](docs/api.md#whenunfold), and [when/unfold/list](docs/api.md#whenunfoldlist) promise-aware anamorphic unfolds that can be used to generate and/or process unbounded lists.
* New [when/poll](docs/api.md#whenpoll) promise-based periodic polling and task execution. Kudos [@scothis](https://github.com/scothis)!

@@ -7,0 +17,0 @@ ### 1.7.1

@@ -139,3 +139,3 @@ /** @license MIT License (c) copyright B Cavalier & J Hann */

function deferDebug(/* id */) {
var d, status, value, origResolve, origReject, origProgress, origThen, id;
var d, status, value, origResolve, origReject, origNotify, origThen, id;

@@ -167,9 +167,14 @@ // Delegate to create a Deferred;

origProgress = d.resolver.progress;
d.progress = d.resolver.progress = function(update) {
origNotify = d.resolver.notify;
d.notify = d.resolver.notify = promiseNotify;
// deferred.progress and deferred.resolver.progress are DEPRECATED.
d.progress = deprecated('deferred.progress', 'deferred.notify', promiseNotify, d);
d.resolver.progress = deprecated('deferred.resolver.progress', 'deferred.resolver.notify', promiseNotify, d.resolver);
function promiseNotify(update) {
// Notify global debug handler, if set
callGlobalHandler('progress', d, update);
return origProgress(update);
};
return origNotify(update);
}

@@ -215,2 +220,6 @@ origResolve = d.resolver.resolve;

whenDebug.isPromise = when.isPromise;
whenDebug.chain = deprecated(
'when.chain(p, resolver)',
'resolver.resolve(p) or resolver.resolve(p.yield(optionalValue))',
when.chain, when);

@@ -217,0 +226,0 @@ // For each method we haven't already replaced, replace it with

@@ -52,4 +52,6 @@ /** @license MIT License (c) copyright B Cavalier & J Hann */

function apply(func, args) {
return when.all(args || []).spread(func);
function apply(func, promisedArgs) {
return when.all(promisedArgs || [], function(args) {
return func.apply(null, args);
});
}

@@ -56,0 +58,0 @@

{
"name": "when",
"version": "1.8.0",
"version": "1.8.1",
"description": "A lightweight Promise and when() implementation, plus other async goodies.",

@@ -31,3 +31,3 @@ "keywords": ["promise", "promises", "deferred", "deferreds", "when", "async", "asynchronous", "cujo"],

"buster": "~0.6",
"jshint": "",
"jshint": "~1.0",
"promise-tests": "*"

@@ -34,0 +34,0 @@ },

@@ -35,3 +35,3 @@ /** @license MIT License (c) copyright B Cavalier & J Hann */

};
return task.apply(null, args);

@@ -38,0 +38,0 @@ };

@@ -79,3 +79,3 @@ /** @license MIT License (c) copyright 2012-2013 original author or authors */

if (result !== undef) {
deferred.progress(result);
deferred.notify(result);
}

@@ -82,0 +82,0 @@ }

@@ -5,11 +5,21 @@ # when.js [![Build Status](https://secure.travis-ci.org/cujojs/when.png)](http://travis-ci.org/cujojs/when)

It passes the [Promises/A Test Suite](https://github.com/domenic/promise-tests), is [frighteningly fast](https://github.com/cujojs/promise-perf-tests#test-results), and is **around 1.3k** when compiled with Google Closure (w/advanced optimizations) and gzipped, and has no external dependencies.
It passes the [Promises/A Test Suite](https://github.com/domenic/promise-tests), is [frighteningly fast](https://github.com/cujojs/promise-perf-tests#test-results), and is **around 1.4k** when compiled with Google Closure (w/advanced optimizations) and gzipped, and has no external dependencies.
# What's New?
### 1.8.1
* Last 1.x.x release before 2.0.0 barring critical fixes.
* To prepare for 2.0.0, [test your code against the dev-200 branch](https://github.com/cujojs/when/tree/dev-200). It is fully API compatible, but has fully asynchronous resolutions.
* Performance improvements for [when/function](docs/api.md#synchronous-functions).
* [Documentation](docs/api.md) updates and fixes. Thanks, [@unscriptable](https://github.com/unscriptable)!
* **DEPRECATED:** `deferred.progress` and `deferred.resolver.progress`. Use [`deferred.notify`](docs/api.md#progress-events) and [`deferred.resolver.notify`](docs/api.md#progress-events) instead.
* **DEPRECATED:** [`when.chain`](docs/api.md#whenchain). Use [`resolver.resolve(promise)`](docs/api.md#resolver) or `resolver.resolve(promise.yield)` ([see `promise.yield`](docs/api.md#yield)) instead.
* **DEPRECATED:** `when/timed` module. Use [`when/delay`](docs/api.md#whendelay) and [`when/timeout`](docs/api.md#whentimeout) modules instead.
### 1.8.0
* New [when/function](docs/api.md#synchronous-functions), [when/node/function](docs/api.md#node-style-asynchronous-functions), and [when/callbacks](docs/api.md#asynchronous-functions) with functional programming goodness, and adapters for turning callback-based APIs into promise-based APIs. Kudos [@riccieri](https://github.com/riccieri)!
* New [when/unfold](api.md#whenunfold), and [when/unfold/list](api.md#whenunfoldlist) promise-aware anamorphic unfolds that can be used to generate and/or process unbounded lists.
* New [when/poll](api.md#whenpoll) promise-based periodic polling and task execution. Kudos [@scothis](https://github.com/scothis)!
* New [when/unfold](docs/api.md#whenunfold), and [when/unfold/list](docs/api.md#whenunfoldlist) promise-aware anamorphic unfolds that can be used to generate and/or process unbounded lists.
* New [when/poll](docs/api.md#whenpoll) promise-based periodic polling and task execution. Kudos [@scothis](https://github.com/scothis)!

@@ -16,0 +26,0 @@ ### 1.7.1

@@ -13,3 +13,3 @@ /** @license MIT License (c) copyright 2011-2013 original author or authors */

*
* @version 1.8.0
* @version 1.8.1
*/

@@ -69,5 +69,5 @@

* @param {*} promiseOrValue
* @returns Guaranteed to return a trusted Promise. If promiseOrValue is a when.js {@link Promise}
* returns promiseOrValue, otherwise, returns a new, already-resolved, when.js {@link Promise}
* whose resolution value is:
* @returns {Promise} Guaranteed to return a trusted Promise. If promiseOrValue
* is trusted, returns promiseOrValue, otherwise, returns a new, already-resolved
* when.js promise whose resolution value is:
* * the resolution value of promiseOrValue if it's a foreign promise, or

@@ -77,3 +77,3 @@ * * promiseOrValue if it's a value

function resolve(promiseOrValue) {
var promise, deferred;
var promise;

@@ -84,26 +84,38 @@ if(promiseOrValue instanceof Promise) {

} else if(isPromise(promiseOrValue)) {
// Assimilate foreign promises
promise = assimilate(promiseOrValue);
} else {
// It's not a when.js promise. See if it's a foreign promise or a value.
if(isPromise(promiseOrValue)) {
// It's a thenable, but we don't know where it came from, so don't trust
// its implementation entirely. Introduce a trusted middleman when.js promise
deferred = defer();
// It's a value, create a fulfilled promise for it.
promise = fulfilled(promiseOrValue);
}
// IMPORTANT: This is the only place when.js should ever call .then() on an
// untrusted promise. Don't expose the return value to the untrusted promise
promiseOrValue.then(
function(value) { deferred.resolve(value); },
function(reason) { deferred.reject(reason); },
function(update) { deferred.progress(update); }
);
return promise;
}
promise = deferred.promise;
/**
* Assimilate an untrusted thenable by introducing a trusted middle man.
* Not a perfect strategy, but possibly the best we can do.
* IMPORTANT: This is the only place when.js should ever call an untrusted
* thenable's then() on an. Don't expose the return value to the untrusted thenable
*
* @param {*} thenable
* @param {function} thenable.then
* @returns {Promise}
*/
function assimilate(thenable) {
var d = defer();
} else {
// It's a value, not a promise. Create a resolved promise for it.
promise = fulfilled(promiseOrValue);
}
// TODO: Enqueue this for future execution in 2.0
try {
thenable.then(
function(value) { d.resolve(value); },
function(reason) { d.reject(reason); },
function(update) { d.progress(update); }
);
} catch(e) {
d.reject(e);
}
return promise;
return d.promise;
}

@@ -239,3 +251,3 @@

var deferred, promise, handlers, progressHandlers,
_then, _progress, _resolve;
_then, _notify, _resolve;

@@ -257,4 +269,4 @@ /**

reject: promiseReject,
// TODO: Consider renaming progress() to notify()
progress: promiseProgress,
progress: promiseNotify, // DEPRECATED: use deferred.notify
notify: promiseNotify,

@@ -266,3 +278,4 @@ promise: promise,

reject: promiseReject,
progress: promiseProgress
progress: promiseNotify, // DEPRECATED: use deferred.notify
notify: promiseNotify
}

@@ -292,9 +305,9 @@ };

// Allow progress handler to transform progress event
deferred.progress(onProgress(update));
deferred.notify(onProgress(update));
} catch(e) {
// Use caught value as progress
deferred.progress(e);
deferred.notify(e);
}
}
: function(update) { deferred.progress(update); };
: function(update) { deferred.notify(update); };

@@ -316,3 +329,3 @@ handlers.push(function(promise) {

*/
_progress = function(update) {
_notify = function(update) {
processQueue(progressHandlers, update);

@@ -334,3 +347,3 @@ return update;

// Make _progress a noop, to disallow progress for the resolved promise.
_progress = identity;
_notify = identity;

@@ -375,6 +388,6 @@ // Notify handlers

/**
* Wrapper to allow _progress to be replaced
* Wrapper to allow _notify to be replaced
*/
function promiseProgress(update) {
return _progress(update);
function promiseNotify(update) {
return _notify(update);
}

@@ -417,3 +430,3 @@ }

var toResolve, toReject, values, reasons, deferred, fulfillOne, rejectOne, progress, len, i;
var toResolve, toReject, values, reasons, deferred, fulfillOne, rejectOne, notify, len, i;

@@ -435,3 +448,3 @@ len = promisesOrValues.length >>> 0;

} else {
progress = deferred.progress;
notify = deferred.notify;

@@ -460,3 +473,3 @@ rejectOne = function(reason) {

if(i in promisesOrValues) {
when(promisesOrValues[i], fulfiller, rejecter, progress);
when(promisesOrValues[i], fulfiller, rejecter, notify);
}

@@ -639,3 +652,6 @@ }

},
resolver.progress
function(update) {
typeof resolver.notify === 'function' && resolver.notify(update);
return update;
}
);

@@ -642,0 +658,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc