Skip to content

The Continuation Pipeline

jmarnold edited this page Jul 7, 2012 · 3 revisions

Overview

jQuery.continuations provides a pipeline for processing continuations. The pipeline is orchestrated by composable policies.

Successful responses

When an ajax request is processed, jquery.continuations uses a global AJAX handler that is registered via the $.ajaxSetup method. The handler parses the server-side continuation, takes care of any callbacks (explained later), and then hands off the continuation to the processing pipeline.

One-off success handlers

Often times it's useful to supply a one-off callback for a particular AJAX request but have the pipeline still get invoked. For these scenarios, a continuationSuccess callback can be supplied to the standard array of $.ajax options. Here is a simple example:

$.ajax({ url: '/continuation', type: 'get', dataType: 'json', continuationSuccess: function(continuation) { console.log(continuation); } });

HTTP errors

Like the success processor, a global error handler is registered via $.ajaxSetup. This handler does one of two things:

  1. If the content-type of the response is JSON, then it assumes that the server sent a continuation. It then parses it and hands it off to the processing pipeline.
  2. If the content-type of the response is not JSON, then a client-side continuation is constructed to represent the error (e.g., 301) and handed off to the processing pipeline.

One-off error handlers

Again, it's often useful to supply one-off handlers for particular requests but still get the power of the conventional processing. For these scenarios, a continuationError callback can be supplied to the standard array of $.ajax options. Here is a simple example:

$.ajax({ url: '/continuation', type: 'get', dataType: 'json', continuationError: function(continuation) { console.log(continuation); } });

Plenty of Defaults

One of the biggest advantages to a pluggable pipeline is that policies can be shared. jquery.continuations includes lots of defaults that you may want to check out.

Events

There are a handful of useful things to know about that happen during the pipeline. These are all exposed through continuation events.

Clone this wiki locally