1

Is it possible to abort a request while its pending?

Code:

var response = await request({uri :”https://www.google.com”})

How would I go about aborting this request?(Not talking about setting timeout)

  • Possible duplicate of [Promise - is it possible to force cancel a promise](https://stackoverflow.com/questions/30233302/promise-is-it-possible-to-force-cancel-a-promise) – Neil Apr 05 '19 at 16:42

1 Answers1

0

You have to call: .cancel

const req = request({uri :”https://www.google.com”})

req.cancel();

Have in mind that it will be tricky to use with await, unless it's happening in another part of the code. If you show as a fully working example, and when you want to abort the request it will be easy to give you an example.


Here is the documentation:

This method cancels the request using Bluebird's cancellation feature.

When .cancel() is called:

  • the promise will neither be resolved nor rejected and the
  • request is aborted.
Marcos Casagrande
  • 37,983
  • 8
  • 84
  • 98
  • 2
    What would be the approach if I want to cancel after - lets say 5 seconds after `request()` is made with `await`? – iam thadiyan Jul 06 '19 at 07:03