async function upload_photo(attachment){
let new_photo = fs.createWriteStream('tmp.jpg')
let new_photo_downloaded = await axios.get(attachment, {
method: 'GET',
responseType: 'stream'
})
new_photo_downloaded.data.pipe(new_photo)
await new Promise((resolve, reject) => {
new_photo.on('finish', resolve)
new_photo.on('error', reject)
})
let options = await api('photos.getUploadServer', {
album_id: config.album_id,
group_id: config.group_id,
access_token: config.access_token
})
let form = new FormData()
form.append('photo', await fs.createReadStream('tmp.jpg'), 'tmp.jpg')
const headers = form.getHeaders()
let response = await axios.post(options.response.upload_url, form, {headers: headers})
let photo_data = response.data
let photo_upload = await api('photos.save',
{
album_id: config.album_id,
group_id: config.group_id,
photos_list: photo_data.photos_list,
server: photo_data.server,
hash: photo_data.hash,
access_token: config.access_token
}
)
let photo = 'photo' + photo_upload.response[0].owner_id + '_' + photo_upload.response[0].id
return photo
}
Почему return срабатывает раньше чем остальной код?