So I am using create-react-native-app to build a project. As you probably know, this uses Expo as a framework when you are developing app.
I am using Expo's FileSystem.downloadAsync() to download files I need. I need multiple files to download, so I run this command inside .map(), something like this:
this.state.files.map(file => {
FileSystem.downloadAsync(file.url, FileSystem.documentDirectory + file.name)
.then(({ uri }) => console.log('Saved this file at: ' + uri))
.catch(console.log('Error when downloading file.'))
})
Now with .then() I know when each file has downloaded, but how do I know when all files has finished downloading?
If I put that in a function and call it, it doesn't wait for it to finish, it just continues to next piece of code.
Could I somehow make that this function returns a new Promise? I think that's a proper way to do it, but I am not sure how do I make it? Where do I put resolve and reject?