You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
exportdefaultconstpromiseTimeout=function(ms,promise){// Create a promise that rejects in <ms> millisecondslettimeout=newPromise((resolve,reject)=>{letid=setTimeout(()=>{clearTimeout(id);reject('Timed out in '+ms+'ms.')},ms)})// Returns a race between our timeout and the passed in promisereturnPromise.race([promise,timeout])}
and then use it like that:
timeoutPromise(5000,evaporate.add(fileConfig))
Max retries
tl;dr
use warn callback with retries counter
_warnCallback(errorMessage,retries,bucket,filename){retries++console.warn(`Evaporate warning after ${retries} tries`,errorMessage)if(retries>MAX_RETRIES){this.cancelUpload(bucket,filename)}returnretries}letretries=0constfileConfig={file: file,name: filename,warn: (errorMessage)=>{retries=this._warnCallback(errorMessage,retries,bucket,filename)},}constfilename=evaporate.add(fileConfig)
For some cases, we might prefer to not race our uploads by timeout (because for example the failure reason that doesn't rely on any time issue), but we still won't want to keep to retry forever, so we can limit our retries by wrapping the uploader like that
classS3Uploader{constructor(){this.uploaderConfig={...}}asynccreateUploader(){if(!this.uploader){this.uploader=awaitEvaporate.create(this.uploaderConfig)}}asyncuploadPhoto(file,filename){letretries=0constfileConfig={file: file,name: filename,warn: (errorMessage)=>{retries=this._warnCallback(errorMessage,retries,bucket,filename)},complete: (xhr,awsObjectKey)=>this._completeCallback(awsObjectKey,retries)}constfilename=awaitthis.uploader.add(fileConfig)returnfilename}asynccancelUpload(bucket,filename){constcancelKey=bucket+'/'+filenametry{awaitthis.uploader.cancel(cancelKey)console.log(`${cancelKey} Canceled!`)}catch(e){console.log(`failed to cancel upload:`,e)}}_warnCallback(errorMessage,retries,bucket,filename){retries++console.warn(`Evaporate warning after ${retries} tries`,errorMessage)if(retries>MAX_RETRIES){this.cancelUpload(bucket,filename)}returnretries}_completeCallback(awsObjectKey,retries){if(retries>0){console.log(`Evaporate complete upload ${awsObjectKey} after ${retries} tries`)}}}exportdefaultS3Uploader
then use it like that:
s3Uploader.uploadPhoto(file,filename)
The text was updated successfully, but these errors were encountered:
Timeout
In case you want to limit your client's upload by time limit you can use Promise.race
(Thanks to https://italonascimento.github.io/applying-a-timeout-to-your-promises/)
you just need to add:
and then use it like that:
Max retries
tl;dr
use warn callback with retries counter
For some cases, we might prefer to not race our uploads by timeout (because for example the failure reason that doesn't rely on any time issue), but we still won't want to keep to retry forever, so we can limit our retries by wrapping the uploader like that
then use it like that:
The text was updated successfully, but these errors were encountered: