jQuery Deferred pipe() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Deferred

Definition

deferred.pipe() filters and/or chains a Deferred. Optional doneFilter, failFilter, and progressFilter map resolve, reject, and progress values. It returns a new Promise (since jQuery 1.6; progress filter since 1.7).

Syntax

Start with these common calls. Keep them short and readable.

jQuery
deferred.pipe(doneFilter [, failFilter [, progressFilter]])

doneFilter(value)     → next success value or Promise
failFilter(reason)    → next reject value (or Promise)
progressFilter(n)     → next progress value

null / omitted filter → pass status & values through
prefer then() in new code
CallWhat it does
deferred.pipe()Learn jQuery deferred.pipe(): filter and chain Deferred values with doneFilter, failFilter, and progressFilter, migrate to then(), examples, pitfalls, and FAQs.

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Build a Deferred (or use a promise from AJAX / helpers).
Step 2Call pipe(doneFilter) — optionally add fail and progress filters.
Step 3Return a value or another promise from the filter.

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

Example 1 — Transform a Resolved Value

Multiply the resolve value in doneFilter; the piped promise gets the new number.

jQuery
var defer = $.Deferred();
var filtered = defer.pipe(function (value) {
  return value * 2;
});

defer.resolve(5);

filtered.done(function (value) {
  console.log(value);  // 10
});
Try It Yourself

How It Works

  1. Create source and pipe. filtered is a new promise wired to the filter.
  2. Resolve with 5. jQuery calls doneFilter(5).
  3. Return 10. That number becomes the resolve value of filtered.

Example 2 — Filter a Reject Value

Pass null for doneFilter and map the rejection reason. A plain return still rejects.

jQuery
var defer = $.Deferred();
var filtered = defer.pipe(null, function (value) {
  return value * 3;
});

defer.reject(6);

filtered.fail(function (value) {
  console.log(value);  // 18
});
Try It Yourself

How It Works

  1. Skip success. First argument is null — only the fail path is filtered.
  2. Reject with 6. failFilter receives 6.
  3. Return 18. The piped promise rejects with 18 (not a recovery to success).

Example 3 — Chain Async Tasks

Return another promise from doneFilter so the chain waits for the next step.

jQuery
function fetchUserId() {
  var d = $.Deferred();
  setTimeout(function () { d.resolve({ id: 42 }); }, 200);
  return d.promise();
}

function fetchProfile(userId) {
  var d = $.Deferred();
  setTimeout(function () {
    d.resolve({ userId: userId, name: "Alex" });
  }, 200);
  return d.promise();
}

fetchUserId().pipe(function (data) {
  return fetchProfile(data.id);
}).done(function (profile) {
  console.log(profile.name);  // Alex
});
Try It Yourself

How It Works

  1. First task. fetchUserId() resolves with { id: 42 }.
  2. Return a promise. The filter starts fetchProfile(42) and returns it.
  3. Wait. The piped chain pauses until that second promise resolves.

Frequently Asked Questions

pipe() returns a new Promise that filters a Deferred’s resolve, reject, and (optionally) progress values. doneFilter runs on resolve; failFilter on reject; progressFilter on notify. Return a value or another promise to feed the next step.
Yes. As of jQuery 1.8, deferred.pipe() is deprecated. Use deferred.then() instead — it replaces pipe() and follows Promises/A+ semantics in jQuery 3+.
done() only registers a side-effect callback — its return value is ignored. pipe() (and then()) use the filter’s return value as the next link’s input.
The piped promise stays rejected, but with the new value. Official pattern: map the reason, then attach .fail(). To recover into success, return a resolved Deferred from failFilter.
Yes. Return a Deferred or Promise from doneFilter; the piped chain waits until that promise settles, then continues with its value.
No. Prefer then(onFulfilled, onRejected) in jQuery 3+. Keep pipe() only when reading or maintaining legacy jQuery 1.x/2.x chains.

Next: $.Deferred() Method — Create Deferred Objects

Learn how to register handlers for notify() progress events.

$.Deferred() Method — Create Deferred Objects tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful