export default const promiseTimeout = function(ms, promise){
// Create a promise that rejects in <ms> milliseconds
let timeout = new Promise((resolve, reject) => {
let id = setTimeout(() => {
clearTimeout(id);
reject('Timed out in '+ ms + 'ms.')
}, ms)
})
// Returns a race between our timeout and the passed in promise
return Promise.race([
promise,
timeout
])
}
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
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: