Thank you for stopping by! I am a full-stack developer that combines the power of entrepreneurship and programming to make the lives of programmers easier.
That is amazing! Never thought of using setTimeout to reject the returned promise.
One question: shouldn't the timeout usually be set on the back-end? Since having it on front-end can vary in behaviour due to bad internet or whatnot (unless that is the reason for using it).
This is very good question, which I haven't asked myself - blind spot in my brain, because I got used to it.
I guess you need timeout on client-side, if server timeout is longer than you want. For example you need to upload big files to this server and as the result timeout of all endpoints increased, not just one.
The second case, is if you guard against slow network. For example 2G connections or if your server is in Europe, but users are in Australia or Japan.
And maybe you actually right and we don't need it in first place. I just thought - "hey, everybody is doing it with timeout, but without cancel. Let me share this"
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
That is amazing! Never thought of using
setTimeout
to reject the returned promise.One question: shouldn't the timeout usually be set on the back-end? Since having it on front-end can vary in behaviour due to bad internet or whatnot (unless that is the reason for using it).
This is very good question, which I haven't asked myself - blind spot in my brain, because I got used to it.
I guess you need timeout on client-side, if server timeout is longer than you want. For example you need to upload big files to this server and as the result timeout of all endpoints increased, not just one.
The second case, is if you guard against slow network. For example 2G connections or if your server is in Europe, but users are in Australia or Japan.
And maybe you actually right and we don't need it in first place. I just thought - "hey, everybody is doing it with timeout, but without cancel. Let me share this"