![](/img/trans.png)
[英]jQuery deferred : use to delay return of function until async call within function complete + get return value
[英]Return value that is within a then async function
我不知道如何返回在第一个函数中找到的变量值的值,然后将它们与then()一起使用,如下所示。
async escribeSolido(contenido: any) {
const ancho = 300;
...
contenido.map(async (item: any) => {
let image = new Jimp(ancho, alto, item.color, (err: any, imagen: any) => {
if (err) {
throw err;
}
});
Jimp.loadFont(Jimp.FONT_SANS_32_BLACK)
.then(font => {
...
return image;
})
.then(async(image) => {
let file = uuid()+'.png';
const path = __dirname +'/public/'+file;
values = await cloudinary.v2.uploader.upload(path, {folder: 'anuncios_basicos'});
/*Return this values*/
console.log('Values -----: ', values);
})
})
});
//return values;
}
我的其他功能
await abService.escribeSolido(contenido)
.then((value: any) => console.log('Values: ', value)) // undefined
.catch((err: any) => console.log(err))
我的结果
Values: undefined
POST /api/anuncio 200 75.451 ms - 463
Values -----: { public_id: 'anuncios_basicos/qnp6s1ptxwzxc0rrwzhp',
....
url:
'http://res.cloudinary.com/dshskwox0/image/upload/v1554922819/anuncios_basicos/qnp6s1ptxwzxc0rrwzhp.png',
secure_url:
'https://res.cloudinary.com/dshskwox0/image/upload/v1554922819/anuncios_basicos/qnp6s1ptxwzxc0rrwzhp.png',
original_filename: 'e59df336-eba1-4b17-9101-fe6bfeed07dc' }
您需要返回console.log语句所在的值。 这会将值返回到由该数组构造的数组。 要从escribeSolido函数返回值数组,只需将return放在地图的前面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.