apocas / docker-modem

Docker Remote API network stack driver.
Apache License 2.0
233 stars 111 forks source link

Add support for abortSignal, to abort requests with an AbortController #132

Closed pimterry closed 3 years ago

pimterry commented 3 years ago

This will make it possible to abort Dockerode requests (https://github.com/apocas/dockerode/issues/629). In practice this looks like:

const abortController = new AbortController();
modem.dial({
  // ...
  abortSignal: abortController.signal
});

// Later, abort the ongoing request:
abortController.abort();
// -> The request returns an AbortError (code: ABORT_ERROR)

I've tested this in Dockerode already, and there will be PR there coming shortly that uses this.

Using this in practice requires either Node 16, or Node 14+ with your own AbortController implementation that polyfills the standard (probably https://www.npmjs.com/package/node-abort-controller).

In other environments nothing breaks, you just can't abort requests, because the signal option is ignored by the HTTP module.

apocas commented 3 years ago

👍 Will ping when published.

apocas commented 3 years ago

Published