XHMM / react-native-cloud-store

A react-native module for icloud drive
https://react-native-cloud-store.vercel.app/docs/install/with-crna
MIT License
68 stars 11 forks source link

Make Persist and Upload resolve/reject when download/upload finishes #6

Closed heyalexchoi closed 2 years ago

heyalexchoi commented 2 years ago

Most straightforward and obvious use of persist and upload IMO is

// persist something
await persist(path)
// do something with it
await copy(path, destination)

which means you want to know when the upload/download is finished. I modified the way the methods work to resolve / reject when the upload / downloads finish or error.

vercel[bot] commented 2 years ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
react-native-cloud-store ✅ Ready (Inspect) Visit Preview Sep 17, 2022 at 11:33PM (UTC)
XHMM commented 2 years ago

Such a long time, 0.8.0 has been released and upload/download now support onProgress option.

If you want to resolve until finished, you can write like this:

await new Promise(async (resolve, reject) => {
  CloudStore.download(path, {
    onProgress(data) {
      if(data.progress === 100) {
        resolve()
      }
    }
  }).catch(reject)
})