question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Returnable async promises

See original GitHub issue

Vue.components allow promise (resolve, reject), but they don’t allow returnable promises. I want to be able to return a promise for async components.
I want to do this:

Vue.component('async-component', function () {
  return new Promise(function (resolve, reject) {
    //step 1
  }).then(function () {
    //step 2
  }).then(function () {
    return { 
      template: '<p>hi</p>' 
    }
  })

})

new Vue({ 
    el: '#demo' 
})

rather than this:

Vue.component('async-component', function (resolve, reject) {
  new Promise(function (resolve, reject) {
    //step 1
  }).then(function () {
    //step 2
  }).then(function () {
    resolve({ 
      template: '<p>hi</p>' 
    })
  }).catch(function (error) {
    reject(error)
  })

})

new Vue({ 
    el: '#demo' 
})

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
JounQincommented, Aug 28, 2016

Ok, thx and sorry again for bothering. @posva

0reactions
posvacommented, Aug 28, 2016

@JounQin Well that’s another subject I’m sure you’ll find information by searching on Google or the forums

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use promises - Learn web development | MDN
A promise is an object returned by an asynchronous function, which represents the current state of the operation. At the time the promise...
Read more >
async/await implicitly returns promise? - Stack Overflow
Yes, an async function will always return a promise. According to the tc39 spec, an async function ...
Read more >
'return await promise' vs 'return promise' in JavaScript
Is there any difference between using 'return await promise' and 'return promise' in asynchronous JavaScript functions?
Read more >
Async and Await in JavaScript, the extension to a promise.
An async function simply implies that a promise will be returned and if a promise is not returned, JavaScript will automatically wrap it...
Read more >
Returning Promises From Async / Await Functions In JavaScript
The return value of an async function is implicitly wrapped in Promise.resolve - if it's not already a promise itself (as in this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found