# Help using promises in javascript?

**URL:** <https://discuss.elastic.co/t/help-using-promises-in-javascript/22079>\
**Category:** Elasticsearch\
**Created:** [February 11, 2015, 12:15am UTC](https://discuss.elastic.co/t/help-using-promises-in-javascript/22079 "2015-02-11T00:15:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElasticSearch\_Users\_](https://avatars.discourse-cdn.com/v4/letter/e/b4bc9f/32.png) [@ElasticSearch\_Users\_](https://discuss.elastic.co/u/ElasticSearch_Users_)\
**Post date:** [February 11, 2015, 12:15am UTC](https://discuss.elastic.co/t/help-using-promises-in-javascript/22079/1 "2015-02-11T00:15:44Z")

</div>

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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/5a52ce5c-2ca1-44f4-ba73-daa5756af183%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:33am UTC](https://discuss.elastic.co/t/help-using-promises-in-javascript/22079/2 "2017-07-06T00:33:48Z")

</div>

Closed on July 6, 2017, 12:33am UTC


