Skip to content

Instantly share code, notes, and snippets.

@rich97
Created August 3, 2012 14:03
Show Gist options
  • Save rich97/3247949 to your computer and use it in GitHub Desktop.
Save rich97/3247949 to your computer and use it in GitHub Desktop.
// I need to use $progress into a callback like this:
callbacks.update = function(data) {
if (data.response !== null) {
if (data.response < 100) {
$progress.custom.update({
completed: data.response
});
return true;
} else {
return false;
}
}
if (data.error !== null) {
$progress.custom.update({
completed: 100,
status: 'error',
message: data.error.message
});
}
// return false by default to prevent an infinate poll scenario
return false;
}
// I have a poll function which polls a script until the update callback is satified that it has the information it needs
function poll(s, d, c) {
if (typeof s === 'undefined' || typeof d === 'undefined' || typeof c === 'undefined') {
return false;
}
if (typeof c.start !== 'undefined') {
c.start();
delete c.start;
}
$.get(s, d, function(result) {
var repost = false;
if (typeof c.update !== 'undefined') {
repost = c.update(result);
}
if (repost === true) {
setTimeout(function() { poll(s, d, c); }, 1000);
} else {
if (typeof c.end !== 'undefined') {
c.end(result);
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment