Edit in JSFiddle

//1: done, 2: cancelled, other: pending
function getPrintingStatus(){
    var d = $.Deferred();
    $.post(
        "/echo/json/",
        {
            json: JSON.stringify( {status: Math.floor(Math.random()*8+1)} ),
            delay: 2
        }
    ).done(function(s){
        d.resolve(s.status);
    }).fail(d.reject); 
    return d.promise();
}

function pollUntilDone(){
    //do something
    return getPrintingStatus()
            .pipe(function(s){
                if(s === 1 || s == 2) {
                    return s;  //if the status is done or cancelled return the status
                }
                //if the status is pending... call this same function
                //and return a deferred...
                return pollUntilDone();
            });
}

$.blockUI({message: "Loading..."});

pollUntilDone()
    .pipe(function(s){ //project the status code to a meaningfull string.
            switch(s){
            case 1:
                return "done";
            case 2:
                return "cancelled";
            }  
    })
    .done(function(s){
        $.unblockUI();
        alert("The status is " + s);
    });

              

              

External resources loaded into this fiddle: