From a2948346fbc853a0bc80fb7c0e3896f48fae5332 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Tue, 18 Aug 2020 03:39:37 -0700 Subject: [PATCH] feat: use native AbortController when possible (#3) --- abort-controller.browser.js | 4 ++++ abort-controller.js | 9 +++++++++ index.js | 2 +- package-lock.json | 2 +- package.json | 9 +++++++-- 5 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 abort-controller.browser.js create mode 100644 abort-controller.js diff --git a/abort-controller.browser.js b/abort-controller.browser.js new file mode 100644 index 0000000..1c36f73 --- /dev/null +++ b/abort-controller.browser.js @@ -0,0 +1,4 @@ +'use strict' +/* eslint-env browser */ + +module.exports = AbortController diff --git a/abort-controller.js b/abort-controller.js new file mode 100644 index 0000000..50a30cd --- /dev/null +++ b/abort-controller.js @@ -0,0 +1,9 @@ +'use strict' + +// Electron has `AbortController` and should use that instead of custom. +// Works around: https://github.com/mysticatea/abort-controller/issues/24 +module.exports = typeof AbortController === 'function' + /* eslint-env browser */ + /* istanbul ignore next */ + ? require('./abort-controller.browser') + : require('abort-controller') diff --git a/index.js b/index.js index 48e369c..d0b54cd 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -const AbortController = require('abort-controller') +const AbortController = require('./abort-controller') /** * Takes an array of AbortSignals and returns a single signal. diff --git a/package-lock.json b/package-lock.json index 8df9701..ed176f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "any-signal", - "version": "1.0.0", + "version": "1.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 230c3b2..72cd9e8 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,9 @@ "description": "Combines an array of AbortSignals into a single signal that is aborted when any signal is", "main": "index.js", "files": [ - "index.js" + "index.js", + "abort-controller.js", + "abort-controller.browser.js" ], "scripts": { "test": "npm run lint && nyc --reporter=lcov --reporter=text ava --verbose", @@ -13,6 +15,9 @@ "keywords": [], "author": "Jacob Heun", "license": "MIT", + "browser": { + "./abort-controller.js": "./abort-controller.browser.js" + }, "dependencies": { "abort-controller": "^3.0.0" }, @@ -35,4 +40,4 @@ "url": "https://github.com/jacobheun/any-signal/issues" }, "homepage": "https://github.com/jacobheun/any-signal#readme" -} +} \ No newline at end of file