Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can a queryTask be executed synchronously? I'd like a feature set to be returned instead of deferred object. Thanks,

share|improve this question
I use queryTask.execute in a cycle because I search all features from several layers that are found inside some rectangle.So I run by layers and for each layer call queryTask.execute and in callback function in its parameter "results" I get some feature set. Because this object does not contain corresponding layer id I'd like to create a new object that contains layer id and feature set. So I need callback function work synchronously. I tried your advice but this does not help: firstly the cycle is ended and only after that the callback or onComplete or .then of deferred begin to work (also in – user32439 Jun 15 '14 at 13:44
up vote 7 down vote accepted

In instances like this, the API returns deferred objects in case you're interested in identifying when more than one request to a server has resolved, but its not something your application logic has to worry about if you're just dealing with one task at a time.

for example, when you call QueryTask.execute() and leverage the in-built callback, you can get a reference to the featureset output you want:

queryTask.execute(query, myCallback, myErrorBack);
myCallback(results) {
  //do something

To work with QueryTask deferreds, you have an additional option to do something like this:

var myDeferred = queryTask.execute(query);
share|improve this answer
Thanks, that makes sense however, I need to create a function/(web service?) that returns a feature set. The callback function performs a task, but I need to return a result, not a promise. How would you go about that? – Matej May 13 '14 at 21:00
sorry, but i'm not sure what youre talking about. – John Gravois May 14 '14 at 18:15
Let me try to rephrase.. If I return a result of a queryTask, I get a promise. Let's say I have a function called myFunction that performs a queryTask based on a polygon geometry. The function call would look something like: var result = myFunction(myGeometry, myMapServiceUrl); Since the function returns before the queryTask completes, the result is of promise type. Perhaps, I need to treat the result as it was an actual featureSet? – Matej May 14 '14 at 18:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.