简体   繁体   中英

Get result from promise resolve in another async function

I'm trying to get the promise resolve result when it ends the Promise in the first function (topromise). Therefore as you'll see below I'm creating another Promise.resolve(pageData) with the value from the last then to try to get the value in my getpromise function.

This is my code:

 function topromise(param){ let pageData; new Promise((resolve, reject)=>{ resolve(param) }) .then((value)=>{ console.log(value) return "hola" }) .then((value)=>{ console.log(value) pageData= "bon jour" return getpromise(Promise.resolve(pageData)) }) } topromise("hello") function getpromise(value){ .then(value=> console.log(value)) //I want to get the pageData result from resolve } 

Your topromise() function is missing a return , and your getpromise function seems to begin in the middle of a method call.

It's very unclear what you're trying to do, but maybe you're going for something like this. This is working code:

 function topromise(param){ let pageData; return Promise.resolve(param) .then((value)=>{ console.log(value) return "hola" }) .then((value)=>{ console.log(value) pageData = "bon jour" return pageData; }) } getpromise(topromise("hello")) function getpromise(value){ value .then(result => console.log(result)) } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM