Advertisement
Anatolyukropov

gotStreamRetryCount

Sep 9th, 2020
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. export const downloadByUrlTest = {
  2. async handler(ctx: Context) {
  3. const { photoUrl } = ctx.params;
  4. let retryCount = 5;
  5.  
  6. return new Promise(async (resolve, reject) => {
  7. const download = () => {
  8. const stream = this.gotInstanse.stream(photoUrl);
  9.  
  10. --retryCount;
  11. stream.once('error', err => {
  12. if (retryCount > 0) {
  13. download();
  14. } else {
  15. reject(err.message);
  16. }
  17. });
  18. stream.once('end', resolve);
  19. };
  20.  
  21. download();
  22. });
  23. },
  24. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement