I am trying to wait for the event "completed" to be finished so I could return the correct value. I am using react native and the type is of EventSubscription
My code is like so which keeps EventSubscription | undefined
in the values variable. How would i get the data.responseBody
in that variable
const values = await Upload.startUpload(options)
.then((uploadId) => {
console.log("Upload started");
Upload.addListener("progress", uploadId, (data) => {
console.log(`Progress: ${data.progress}%`);
});
Upload.addListener("error", uploadId, (data) => {});
Upload.addListener("cancelled", uploadId, (data) => {});
const completeSub = Upload.addListener("completed", uploadId, (data) => {
console.log("Completed!", data);
return data.responseBody;
});
return completeSub;
})
.catch((err) => {
console.log("Upload error!", err);
return undefined;
});
return values
I found a way to do this in DOM js in this link How to let JavaScript wait until certain event happens?