well.js
function chain(promiseOrValue, resolver, resolveValue) {
            var useResolveValue = arguments.length > 2;

            return well(promiseOrValue,
                function (val) {
                    val = useResolveValue ? resolveValue : val;
                    resolver.resolve(val);
                    return val;
                },
                function (reason) {
                    resolver.reject(reason);
                    return rejected(reason);
                },
                function (update) {
                    typeof resolver.notify === 'function' && resolver.notify(update);
                    return update;
                }
            );
        }
function chain(promiseOrValue, resolver, resolveValue) {
            var useResolveValue = arguments.length > 2;

            return well(promiseOrValue,
                function (val) {
                    val = useResolveValue ? resolveValue : val;
                    resolver.resolve(val);
                    return val;
                },
                function (reason) {
                    resolver.reject(reason);
                    return rejected(reason);
                },
                function (update) {
                    typeof resolver.notify === 'function' && resolver.notify(update);
                    return update;
                }
            );
        }
function chain ( promiseOrValue , resolver , resolveValue ) { var useResolveValue = arguments . length > 2 ; return well ( promiseOrValue , function ( val ) { val = useResolveValue ? resolveValue : val ; resolver . resolve ( val ) ; return val ; } , function ( reason ) { resolver . reject ( reason ) ; return rejected ( reason ) ; } , function ( update ) { typeof resolver . notify === 'function' && resolver . notify ( update ) ; return update ; } ) ; }
Ensure that resolution of promiseOrValue will trigger resolver with the
value or reason of promiseOrValue, or instead with resolveValue if it is provided.

@param promiseOrValue
@param {Object} resolver
@param {function} resolver.resolve
@param {function} resolver.reject
@param {*} [resolveValue]
@returns {Promise}
Ensure that resolution of promiseOrValue will trigger resolver with the value or reason of promiseOrValue or instead with resolveValue if it is provided .