Last active
June 1, 2017 14:39
-
-
Save sibsfinx/3f59bb28564c49e9ca21ac72b68a5e6b to your computer and use it in GitHub Desktop.
Can't make promise return value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// need to execute a chain of promises (using then()) | |
// and make/call a function that will return a value (not a promise object) | |
p = (fn) => { | |
return new Promise((resolve, reject) => { | |
setTimeout( () => { | |
resolve(fn.call()); | |
}, 1000); | |
}); | |
}; | |
log = () => { | |
console.log('step'); | |
return 1; | |
} | |
prom = null; | |
prom = p(log).then((res) => { | |
return p(log); | |
}).then((res) => { | |
return p(log); | |
}).then((res) => { | |
return 1; | |
}); | |
async function aspr() { | |
r = await prom.then((v) => { | |
window.result = v; | |
}); | |
console.log(window.result); | |
return window.result; | |
} | |
aspr(); |
dreucodi
commented
Jun 1, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment