Returning a promise in JavaScript

187 views Asked by At

I have a promise here:

myPromise: ->
  return new Em.RSVP.Promise (resolve, reject) ->
    # ...
    resolve 5

How do I write a function to return the promise from myPromise()?

This is what I've tried:

myPromise2: ->
  return myPromise()

myPromise2().then ->
   console.log 'this is never called!'
1

There are 1 answers

0
nnyby On BEST ANSWER

I figured it out!

myPromise2: ->
  new Em.RSVP.Promise (resolve, reject) ->
    myPromise()
    resolve()