3

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

nmtoken
13.6k5 gold badges39 silver badges91 bronze badges
asked May 12, 2014 at 21:29
1
  • 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 Commented Jun 15, 2014 at 13:44

1 Answer 1

7

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);
myDeferred.then(...
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
answered May 12, 2014 at 21:47
3
  • 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? Commented May 13, 2014 at 21:00
  • sorry, but i'm not sure what youre talking about. Commented May 14, 2014 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? Commented May 14, 2014 at 18:44

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.