Skip to content

Commit

Permalink
Refactored AbortController;
Browse files Browse the repository at this point in the history
  • Loading branch information
DigitalBrainJS committed Dec 6, 2020
1 parent 5d4aafe commit 6255fb1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 737 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
/node_modules/
/trash/
/.idea/
/test/tests/decorators.js
/test/tests/decorators.legacy.js
40 changes: 21 additions & 19 deletions lib/abort-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,27 @@ const _aborted = Symbol('aborted');
const _events = Symbol('events');
const _abort = Symbol('abort');

const nativeAbortController= (()=>{
try {
if (typeof AbortController === 'function') {
const controller = new AbortController();
if (controller.toString() === '[object AbortController]' &&
controller.constructor.toString().indexOf('[native code]') !== -1) {
return AbortController;
}
}
} catch (e) {
}
})()

/**
* AbortSignalPolyfill class
* @alias CPromise.AbortSignalPolyfill
*/

class AbortSignalEx {
class AbortSignal {
/**
* Constructs a new AbortSignalPolyfill instance
* Constructs a new AbortSignal instance
*/

constructor() {
Expand Down Expand Up @@ -121,7 +134,7 @@ class AbortSignalEx {
* AbortController class
*/

class AbortControllerEx {
class AbortController {
/**
* Constructs new AbortController instance
*/
Expand All @@ -131,11 +144,11 @@ class AbortControllerEx {

/**
* returns the signal of the controller
* @returns {AbortSignalEx}
* @returns {AbortSignal}
*/

get signal() {
return this[_signal] || (this[_signal] = new AbortSignalEx());
return this[_signal] || (this[_signal] = new AbortSignal());
}

set signal(v) {
Expand Down Expand Up @@ -173,20 +186,9 @@ const isAbortController = (thing) => {
};

module.exports = {
AbortController: (()=>{
try {
if (typeof AbortController === 'function') {
const controller = new AbortController();
if (controller.toString() === '[object AbortController]' &&
controller.constructor.toString().indexOf('[native code]') !== -1) {
return AbortController;
}
}
} catch (e) {
}
})() || AbortControllerEx,
AbortControllerEx,
AbortSignalEx,
AbortController: nativeAbortController || AbortController,
AbortControllerEx: AbortController,
AbortSignalEx: AbortSignal,
isAbortSignal,
isAbortController
};
Loading

0 comments on commit 6255fb1

Please sign in to comment.