等到内心承诺在返回之前解决

时间:2018-05-15 20:11:27

标签: javascript promise async-await

我有一个返回null值的函数,而不是在返回之前等待内部promise的解析。

我尝试过使用async / await,但没有成功。 getTargets函数需要返回upload_url,而不是promise。

    function getTargets (currentChunk) {
        let chunkArray = [];

        // split chunk strings into key value pairs, then add them to an array
        for(let parameter of currentChunk) {
            let keyValue = parameter.split('=');
            chunkArray[keyValue[0]] = keyValue[1];
        }

        for(let file of myFiles) {
            if (file.name === chunkArray['resumableFilename']) {
                myService.getUploadUrl(file.id, chunkArray['resumableChunkNumber'], file.upload_id).then((response) => {
                    console.log(response.upload_url);
                    return response.upload_url;
                });
            }
        }
    }

0 个答案:

没有答案
相关问题