Help using promises in javascript?

Hi I'm trying to create a flotchart with es but I don't quite know how to
resolve my promise. Here is the code. When I log the promise in my function
I show it's in a pending state but I don't understand how to resolve it AND
get the results into an object that I can then traverse response.hits.hits.

So I guess a few questions:
Do I resolve the promise in Main or in dashboardFlotTwo?
When I resolve it, how do I get the object out into a value I can work with?
Is there a better way to do this?

Any help appreciated.

Vihar

function MainCtrl() {

promise = new Promise(function(resolve,reject)

client.search({

  index: events,

  body: {  query: {  bool: { must : [ { range : { "@timestamp" : { "gt" 

: "now-8h" } } }

        ] //end must

      } //end bool

    } //end query

  } //end body

});

});

}

function dashboardFlotTwo() {

console.log(promise);

...

}

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/5a52ce5c-2ca1-44f4-ba73-daa5756af183%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.