Ale*_*min 4 async-await reactjs react-native react-redux react-native-fs
我需要在按下按钮时下载一组图像。目前,我正在使用以下方式这样做react-native-fs:
const downloadImageItem = async (imgUrl, id) => {
const path = `${RNFS.DocumentDirectoryPath}/${id}.jpg`;
RNFS.downloadFile({
fromUrl: imgUrl,
toFile: path,
});
};
Run Code Online (Sandbox Code Playgroud)
const downloadImages = async (items) => {
for (const item of items) {
if (item.images.length) {
await downloadImageItem(item.images[0].thumb, item.images[0].id);
}
}
return Promise.resolve();
};
Run Code Online (Sandbox Code Playgroud)
从我的减速器中为 3 种类型的项目调用函数:
await downloadImages(items_one);
await downloadImages(items_two);
await downloadImages(items_three);
Run Code Online (Sandbox Code Playgroud)
我的问题是有时我会收到一条错误消息: 过多的待处理回调数:501
有没有更好的方法来做同样的事情,这样错误就不会出现?
| 归档时间: |
|
| 查看次数: |
9315 次 |
| 最近记录: |