Portal.queryItems callback function execution timing

1784
2
Jump to solution
05-11-2016 06:33 AM
NartTamash
New Contributor III

Hi all,

I've got the following scenario...I'm querying my local Portal for certain items and then I am processing them using a callback function, as soon as the query returns them.

globalVariable
     //...

     function doSomeOtherStuff() {
          //do some other stuff
          //requires the updated globalVariable
     };

     Portal.queryItems(params).then(processItems)
     
     doSomeOtherStuff();

     function processItems(items) {
          //do something
          //update globalVariable
     };

     //...

Giving this is an async call, other things (i.e. doSomeOtherStuff()) carry on while the query is finalised and the items processed.

How can I wait for the processItems() to complete before doing anything else (so a synchronous operation in a sense)?

The processItems function updates a global variable that I need to use in doSomeOtherStuff() and carry on with the logic. I can't execute doSomeOtherStuff() within processItems() because due to the nature of it, it will take doSomeOtherStuff() out of scope.

Hope this makes sense, I've tried to simplify as much as possible.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
2 Replies
RobertScheitlin__GISP
MVP Emeritus

Nart,

  This is where a Deferred comes into play.

dojo/Deferred — The Dojo Toolkit - Reference Guide

NartTamash
New Contributor III

Right...so what I needed was a chained promise. Sort of tried that before but didn't work cause I didn't know what I was doing

Always on the watch, Robert! Appreciate it!

0 Kudos