I'm looking at both PromiseJS and ES6 for something similar to a CompletableFuture, but couldn't find any.
Any suggestions how this can be achieved in javascript? Thanks
Note: Promise.resolve()
isn't suitable, unless you can create the Promise
object first and complete it later.
Update
As all answers pointed out, the correct way is to use Promise
's constructor:
new Promise((resolve, reject) => { resolve(data); })