Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canceling request: "r.cancel is not a function" #1066

Closed
1 task done
garyo opened this issue Feb 14, 2020 · 2 comments
Closed
1 task done

Canceling request: "r.cancel is not a function" #1066

garyo opened this issue Feb 14, 2020 · 2 comments

Comments

@garyo
Copy link

garyo commented Feb 14, 2020

What would you like to discuss?

I'm trying to cancel an ongoing request like this:

      const request = got(url, { retry: 0 })
      function startTimer(r: typeof request) {
        return setTimeout(() => r.cancel(), timeoutMs)
      }
      const timer = startTimer(request)
      const response = await request
      clearTimeout(timer)
      // check response or handle error

but I get TypeError: r.cancel is not a function at runtime. Typescript thinks all is OK at compile time and can see that request and r are of type CancelableRequest.

I must be doing something wrong; I'm new to got.
(I'm trying this method because I have a server that may be down and I don't want to wait a long time for ECONNREFUSED -- I tried setting all the timeouts in options.timeout, but they had no effect, so I'm trying this.)

Checklist

  • I have read the documentation.
@szmarczak
Copy link
Collaborator

I cannot reproduce with your example: https://runkit.com/szmarczak/5e46bac55abbb10013e2e34a

@garyo
Copy link
Author

garyo commented Feb 16, 2020

OK, I switched to another lib anyway. Must have been my error. Closing.

@garyo garyo closed this as completed Feb 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants