K
K
krlljs2016-05-05 02:35:42
JavaScript
krlljs, 2016-05-05 02:35:42

One nodejs module uses a promise, but why does a promise return a Promise { }?

var start = function(id,fields) {
  return VK.call('friends.get', {
      user_id: id,
      fields: fields
    })
    .then(response => {
    	return _.filter(response.items, items => {
    		return items.online === 1
    	})
    })
    .catch(e => console.log(e))
}

start();
I expect it to return a response object, but it doesn't. Promise { <pending> }Is this a feature of promises, or is the code written this way? https://github.com/olnaz/node-vkapi

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Osher, 2016-05-05
@krlljs

1) RTFM
2) start().then(friends => { /* your code *? });

B
bromzh, 2016-05-05
@bromzh

The VK.call method returns a promise. The start function returns the result of VK.call execution.
Why should it suddenly return a response?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question