The Stack Overflow podcast is back! Listen to an interview with our new CEO.
3 replaced http://programmers.stackexchange.com/ with https://softwareengineering.stackexchange.com/
source | link

I'm using an offline application's javascript API and I'd like to know if I can use deferred objects to handle the callbacks. The API calls do not use HTTP, the calls are to and from the applications local database.

The only way I've been able to display information is by using 'setTimeout' on subsequent calls, which I know, is terrible! So I have a long list of callbacks and timeouts.

var jsObj = {};
var anotherObj = {};

//first async call
methodName("arg1", jsObj, callback);

function callback(result){

  jsObj["data"] = result;

}

//second async call
setTimeout(function(){methodName("arg1", anotherObj, callback2);}, 200);

function callback2(result){

  jsObj["data"] = result;

}

//wait
setTimeout(function(){

  $("#content").html(JSON.stringify(jsObj));

},300);

Is there anyway to refactor this? Any advice is appreciated. I've looked at the following postpost, but I'm not sure it would work. I'm aware I can create custom deferred objects (jQuery), but altering the API to use this or any other method of promise objects seems unrealistic.

I'm using an offline application's javascript API and I'd like to know if I can use deferred objects to handle the callbacks. The API calls do not use HTTP, the calls are to and from the applications local database.

The only way I've been able to display information is by using 'setTimeout' on subsequent calls, which I know, is terrible! So I have a long list of callbacks and timeouts.

var jsObj = {};
var anotherObj = {};

//first async call
methodName("arg1", jsObj, callback);

function callback(result){

  jsObj["data"] = result;

}

//second async call
setTimeout(function(){methodName("arg1", anotherObj, callback2);}, 200);

function callback2(result){

  jsObj["data"] = result;

}

//wait
setTimeout(function(){

  $("#content").html(JSON.stringify(jsObj));

},300);

Is there anyway to refactor this? Any advice is appreciated. I've looked at the following post, but I'm not sure it would work. I'm aware I can create custom deferred objects (jQuery), but altering the API to use this or any other method of promise objects seems unrealistic.

I'm using an offline application's javascript API and I'd like to know if I can use deferred objects to handle the callbacks. The API calls do not use HTTP, the calls are to and from the applications local database.

The only way I've been able to display information is by using 'setTimeout' on subsequent calls, which I know, is terrible! So I have a long list of callbacks and timeouts.

var jsObj = {};
var anotherObj = {};

//first async call
methodName("arg1", jsObj, callback);

function callback(result){

  jsObj["data"] = result;

}

//second async call
setTimeout(function(){methodName("arg1", anotherObj, callback2);}, 200);

function callback2(result){

  jsObj["data"] = result;

}

//wait
setTimeout(function(){

  $("#content").html(JSON.stringify(jsObj));

},300);

Is there anyway to refactor this? Any advice is appreciated. I've looked at the following post, but I'm not sure it would work. I'm aware I can create custom deferred objects (jQuery), but altering the API to use this or any other method of promise objects seems unrealistic.

2 added 147 characters in body
source | link

I'm using an offline application's javascript API and I'd like to know if I can use deferred objects to handle the callbacks. The API calls do not use HTTP, the calls are to and from the applications local database.

The only way I've been able to display information is by using 'setTimeout' on subsequent calls, which I know, is terrible! So I have a long list of callbacks and timeouts.

var jsObj = {};
var anotherObj = {};

//first async call
methodName("arg1", jsObj, callback);

function callback(result){

  jsObj["data"] = result;

}

//second async call
setTimeout(function(){methodName("arg1", anotherObj, callback2);}, 200);

function callback2(result){

  jsObj["data"] = result;

}

//wait
setTimeout(function(){

  $("#content").html(JSON.stringify(jsObj));

},300);

Is there anyway to refactor this? Any advice is appreciated. I've looked at the following post, but I'm not sure it would work. I'm aware I can create custom deferred objects (jQuery), but altering the API to use this or any other method of promise objects seems unrealistic.

I'm using an offline application's javascript API and I'd like to know if I can use deferred objects to handle the callbacks. The API calls do not use HTTP, the calls are to and from the applications local database.

The only way I've been able to display information is by using 'setTimeout' on subsequent calls, which I know, is terrible! So I have a long list of callbacks and timeouts.

var jsObj = {};
var anotherObj = {};

//first async call
methodName("arg1", jsObj, callback);

function callback(result){

  jsObj["data"] = result;

}

//second async call
setTimeout(function(){methodName("arg1", anotherObj, callback2);}, 200);

function callback2(result){

  jsObj["data"] = result;

}

//wait
setTimeout(function(){

  $("#content").html(JSON.stringify(jsObj));

},300);

Is there anyway to refactor this? Any advice is appreciated. I've looked at the following post, but I'm not sure it would work.

I'm using an offline application's javascript API and I'd like to know if I can use deferred objects to handle the callbacks. The API calls do not use HTTP, the calls are to and from the applications local database.

The only way I've been able to display information is by using 'setTimeout' on subsequent calls, which I know, is terrible! So I have a long list of callbacks and timeouts.

var jsObj = {};
var anotherObj = {};

//first async call
methodName("arg1", jsObj, callback);

function callback(result){

  jsObj["data"] = result;

}

//second async call
setTimeout(function(){methodName("arg1", anotherObj, callback2);}, 200);

function callback2(result){

  jsObj["data"] = result;

}

//wait
setTimeout(function(){

  $("#content").html(JSON.stringify(jsObj));

},300);

Is there anyway to refactor this? Any advice is appreciated. I've looked at the following post, but I'm not sure it would work. I'm aware I can create custom deferred objects (jQuery), but altering the API to use this or any other method of promise objects seems unrealistic.

1
source | link

How to handle asynchronous calls in an offline application

I'm using an offline application's javascript API and I'd like to know if I can use deferred objects to handle the callbacks. The API calls do not use HTTP, the calls are to and from the applications local database.

The only way I've been able to display information is by using 'setTimeout' on subsequent calls, which I know, is terrible! So I have a long list of callbacks and timeouts.

var jsObj = {};
var anotherObj = {};

//first async call
methodName("arg1", jsObj, callback);

function callback(result){

  jsObj["data"] = result;

}

//second async call
setTimeout(function(){methodName("arg1", anotherObj, callback2);}, 200);

function callback2(result){

  jsObj["data"] = result;

}

//wait
setTimeout(function(){

  $("#content").html(JSON.stringify(jsObj));

},300);

Is there anyway to refactor this? Any advice is appreciated. I've looked at the following post, but I'm not sure it would work.