Skip to content

Instantly share code, notes, and snippets.

@magixsource
Created June 12, 2014 09:48
Show Gist options
  • Save magixsource/68faed725d7e884eb11e to your computer and use it in GitHub Desktop.
Save magixsource/68faed725d7e884eb11e to your computer and use it in GitHub Desktop.
blocking function depend non-blocking function
// XHR lib use jquery
// jsonp url
var url = "http://www.google.com/jsonp/search.html"
// query keys
var array = new Array("google.com","baidu.com","yahoo.com","bing.com","soso.com");
//$.getJSON is a non-blocking function,load jsonp data here
function nonBlockingLoad(o){
$.getJSON(url+"?query="+o+"&type=text&nodeNo=87&callback=?",function(data){
if(data.pass){
//TODO
}else{
blockingInvoke();
}
});
}
// This is a normal blocking function
function blockingInvoke(){
var item = array.pop();
if(item){
nonBlockingLoad(obj);
}
}
// trigger
$("#btn").bind('click',function(){
blockingInvoke();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment