Question on using Dojo/Deferred

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

Question on using Dojo/Deferred

Harry Devine
I have a Dojo store that is being created using the following code:

var store = new Observable(new RequestMemory({url: "getData.php"}));

The store is used to populate a Dojo Pie chart.  The issue is that the getData.php file takes some time to run.  The Pie chart does get created but after a few seconds of waiting.  A side effect of this is that I have a Legend I'm trying to build for the chart and that never gets rendered at all.  I suspect because of the asynchronous-ness of the operation to retrieve the data.

I figured I'd wrap the whole process into a Dojo/Deferred and only render that chart and create the legend once the data store has been created as above.  But I can't seem to figure out how to do it.  I've used Deferred before and read the documentation, but it doesn't really cover what I'm trying to do in this case.

So, how would one construct a Dojo/Deferred so that it would make the data store call above, wait for the operation complete, then move on to creating the chart and legend?


Dojo Toolkit:

[hidden email]
To unsubscribe, visit:
Reply | Threaded
Open this post in threaded view

Re: Question on using Dojo/Deferred

Looking at the code, RequestMemory seems to be a "sub-class" (in dojo/declare sense) of Memory.
And according to the docs at, Memory returns a promise.
So if your question is about how to consume a promise, it would be:

var asyncFunctionPromise = asyncFunction();
// Write business logic to execute after the async function completes
asyncFunctionPromise.then(function(args) {
 // business logic

I created some examples here for my reference, take a look to see if it helps