@taraflex/cancelation-token
Advanced tools
| import { ExtendableError } from '@taraflex/error'; | ||
| declare class CancelationTokenError extends ExtendableError { | ||
| } | ||
| interface ICancelationToken { | ||
| connect(reason?: unknown): () => void; | ||
| readonly cancel: (reason?: unknown) => void; | ||
| } | ||
| declare class CancelationToken implements ICancelationToken { | ||
| static CancelationTokenError: typeof CancelationTokenError; | ||
| protected readonly connections: Set<(reason?: unknown) => void>; | ||
| protected _canceled: boolean; | ||
| get canceled(): boolean; | ||
| check(): void; | ||
| connect(cb: (reason?: unknown) => void): () => boolean; | ||
| readonly cancel: (reason?: unknown) => void; | ||
| fork<T extends ICancelationToken = this>(CancelationTokenClass?: { | ||
| new (): T; | ||
| }): T; | ||
| } | ||
| export { CancelationTokenError, ICancelationToken, CancelationToken }; |
| 'use strict'; | ||
| Object.defineProperty(exports, '__esModule', { value: true }); | ||
| const error = require('@taraflex/error'); | ||
| class CancelationTokenError extends error.ExtendableError { | ||
| } | ||
| class CancelationToken { | ||
| constructor() { | ||
| this.connections = new Set(); | ||
| this._canceled = false; | ||
| this.cancel = (reason) => { | ||
| if (!this._canceled) { | ||
| this._canceled = true; | ||
| let err = undefined; | ||
| this.connections.forEach(c => { | ||
| try { | ||
| c(reason); | ||
| } | ||
| catch (e) { | ||
| err = e !== null && e !== void 0 ? e : err; | ||
| } | ||
| }); | ||
| this.connections.clear(); | ||
| if (err !== undefined) { | ||
| throw err; | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| get canceled() { | ||
| return this._canceled; | ||
| } | ||
| check() { | ||
| if (this._canceled) { | ||
| throw new CancelationTokenError('[CancelationToken.check]'); | ||
| } | ||
| } | ||
| connect(cb) { | ||
| if (this._canceled) { | ||
| throw new CancelationTokenError('[CancelationToken.connect]'); | ||
| } | ||
| this.connections.add(cb); | ||
| return this.connections.delete.bind(this.connections, cb); | ||
| } | ||
| fork(CancelationTokenClass = CancelationToken) { | ||
| const ctoken = new CancelationTokenClass(); | ||
| ctoken.connect(this.connect(ctoken.cancel)); | ||
| return ctoken; | ||
| } | ||
| } | ||
| CancelationToken.CancelationTokenError = CancelationTokenError; | ||
| exports.CancelationToken = CancelationToken; | ||
| exports.CancelationTokenError = CancelationTokenError; | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sources":["../index.ts"],"sourcesContent":["import { ExtendableError } from '@taraflex/error';\n\nexport class CancelationTokenError extends ExtendableError {}\n\nexport interface ICancelationToken {\n connect(reason?: unknown): () => void;\n readonly cancel: (reason?: unknown) => void;\n}\n\nexport class CancelationToken implements ICancelationToken {\n static CancelationTokenError = CancelationTokenError;\n\n protected readonly connections = new Set<(reason?: unknown) => void>();\n protected _canceled = false;\n get canceled() {\n return this._canceled;\n }\n check() {\n if (this._canceled) {\n throw new CancelationTokenError('[CancelationToken.check]');\n }\n }\n connect(cb: (reason?: unknown) => void) {\n if (this._canceled) {\n throw new CancelationTokenError('[CancelationToken.connect]');\n }\n this.connections.add(cb);\n return this.connections.delete.bind(this.connections, cb);\n }\n readonly cancel = (reason?: unknown) => {\n if (!this._canceled) {\n this._canceled = true;\n let err = undefined;\n this.connections.forEach(c => {\n try {\n c(reason);\n } catch (e) {\n err = e ?? err;\n }\n });\n this.connections.clear();\n if (err !== undefined) {\n throw err;\n }\n }\n };\n fork<T extends ICancelationToken = this>(CancelationTokenClass: { new (): T } = CancelationToken as any) {\n const ctoken = new CancelationTokenClass();\n ctoken.connect(this.connect(ctoken.cancel));\n return ctoken;\n }\n}\n"],"names":["ExtendableError"],"mappings":";;;;;;AAEM,MAAO,qBAAsB,SAAQA,qBAAe,CAAA;AAAG,CAAA;MAOhD,gBAAgB,CAAA;AAA7B,IAAA,WAAA,GAAA;AAGuB,QAAA,IAAA,CAAA,WAAW,GAAG,IAAI,GAAG,EAA8B,CAAC;QAC7D,IAAS,CAAA,SAAA,GAAG,KAAK,CAAC;AAgBnB,QAAA,IAAA,CAAA,MAAM,GAAG,CAAC,MAAgB,KAAI;AACnC,YAAA,IAAI,CAAC,IAAI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AAM,CAAC,MAAM,CAAC,CAAC,CAAC;AAC5C,QAAA,OAAO,MAAM,CAAC;KACjB;;AAxCM,gBAAqB,CAAA,qBAAA,GAAG,qBAAH;;;;;"} |
| import { ExtendableError } from '@taraflex/error'; | ||
| class CancelationTokenError extends ExtendableError { | ||
| } | ||
| class CancelationToken { | ||
| constructor() { | ||
| this.connections = new Set(); | ||
| this._canceled = false; | ||
| this.cancel = (reason) => { | ||
| if (!this._canceled) { | ||
| this._canceled = true; | ||
| let err = undefined; | ||
| this.connections.forEach(c => { | ||
| try { | ||
| c(reason); | ||
| } | ||
| catch (e) { | ||
| err = e !== null && e !== void 0 ? e : err; | ||
| } | ||
| }); | ||
| this.connections.clear(); | ||
| if (err !== undefined) { | ||
| throw err; | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| get canceled() { | ||
| return this._canceled; | ||
| } | ||
| check() { | ||
| if (this._canceled) { | ||
| throw new CancelationTokenError('[CancelationToken.check]'); | ||
| } | ||
| } | ||
| connect(cb) { | ||
| if (this._canceled) { | ||
| throw new CancelationTokenError('[CancelationToken.connect]'); | ||
| } | ||
| this.connections.add(cb); | ||
| return this.connections.delete.bind(this.connections, cb); | ||
| } | ||
| fork(CancelationTokenClass = CancelationToken) { | ||
| const ctoken = new CancelationTokenClass(); | ||
| ctoken.connect(this.connect(ctoken.cancel)); | ||
| return ctoken; | ||
| } | ||
| } | ||
| CancelationToken.CancelationTokenError = CancelationTokenError; | ||
| export { CancelationToken, CancelationTokenError }; | ||
| //# sourceMappingURL=index.mjs.map |
| {"version":3,"file":"index.mjs","sources":["../index.ts"],"sourcesContent":["import { ExtendableError } from '@taraflex/error';\n\nexport class CancelationTokenError extends ExtendableError {}\n\nexport interface ICancelationToken {\n connect(reason?: unknown): () => void;\n readonly cancel: (reason?: unknown) => void;\n}\n\nexport class CancelationToken implements ICancelationToken {\n static CancelationTokenError = CancelationTokenError;\n\n protected readonly connections = new Set<(reason?: unknown) => void>();\n protected _canceled = false;\n get canceled() {\n return this._canceled;\n }\n check() {\n if (this._canceled) {\n throw new CancelationTokenError('[CancelationToken.check]');\n }\n }\n connect(cb: (reason?: unknown) => void) {\n if (this._canceled) {\n throw new CancelationTokenError('[CancelationToken.connect]');\n }\n this.connections.add(cb);\n return this.connections.delete.bind(this.connections, cb);\n }\n readonly cancel = (reason?: unknown) => {\n if (!this._canceled) {\n this._canceled = true;\n let err = undefined;\n this.connections.forEach(c => {\n try {\n c(reason);\n } catch (e) {\n err = e ?? err;\n }\n });\n this.connections.clear();\n if (err !== undefined) {\n throw err;\n }\n }\n };\n fork<T extends ICancelationToken = this>(CancelationTokenClass: { new (): T } = CancelationToken as any) {\n const ctoken = new CancelationTokenClass();\n ctoken.connect(this.connect(ctoken.cancel));\n return ctoken;\n }\n}\n"],"names":[],"mappings":";;AAEM,MAAO,qBAAsB,SAAQ,eAAe,CAAA;AAAG,CAAA;MAOhD,gBAAgB,CAAA;AAA7B,IAAA,WAAA,GAAA;AAGuB,QAAA,IAAA,CAAA,WAAW,GAAG,IAAI,GAAG,EAA8B,CAAC;QAC7D,IAAS,CAAA,SAAA,GAAG,KAAK,CAAC;AAgBnB,QAAA,IAAA,CAAA,MAAM,GAAG,CAAC,MAAgB,KAAI;AACnC,YAAA,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;AACjB,gBAAA,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;gBACtB,IAAI,GAAG,GAAG,SAAS,CAAC;AACpB,gBAAA,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,IAAG;oBACzB,IAAI;wBACA,CAAC,CAAC,MAAM,CAAC,CAAC;AACb,qBAAA;AAAC,oBAAA,OAAO,CAAC,EAAE;wBACR,GAAG,GAAG,CAAC,KAAD,IAAA,IAAA,CAAC,cAAD,CAAC,GAAI,GAAG,CAAC;AAClB,qBAAA;AACL,iBAAC,CAAC,CAAC;AACH,gBAAA,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;gBACzB,IAAI,GAAG,KAAK,SAAS,EAAE;AACnB,oBAAA,MAAM,GAAG,CAAC;AACb,iBAAA;AACJ,aAAA;AACL,SAAC,CAAC;KAML;AArCG,IAAA,IAAI,QAAQ,GAAA;QACR,OAAO,IAAI,CAAC,SAAS,CAAC;KACzB;IACD,KAAK,GAAA;QACD,IAAI,IAAI,CAAC,SAAS,EAAE;AAChB,YAAA,MAAM,IAAI,qBAAqB,CAAC,0BAA0B,CAAC,CAAC;AAC/D,SAAA;KACJ;AACD,IAAA,OAAO,CAAC,EAA8B,EAAA;QAClC,IAAI,IAAI,CAAC,SAAS,EAAE;AAChB,YAAA,MAAM,IAAI,qBAAqB,CAAC,4BAA4B,CAAC,CAAC;AACjE,SAAA;AACD,QAAA,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AACzB,QAAA,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;KAC7D;IAkBD,IAAI,CAAqC,wBAAuC,gBAAuB,EAAA;AACnG,QAAA,MAAM,MAAM,GAAG,IAAI,qBAAqB,EAAE,CAAC;AAC3C,QAAA,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;AAC5C,QAAA,OAAO,MAAM,CAAC;KACjB;;AAxCM,gBAAqB,CAAA,qBAAA,GAAG,qBAAH;;;;"} |
+21
| MIT License | ||
| Copyright (c) 2017 Alexander Taratin | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
+26
-9
| { | ||
| "name": "@taraflex/cancelation-token", | ||
| "version": "0.0.2", | ||
| "version": "0.0.3", | ||
| "description": "", | ||
| "license": "ISC", | ||
| "author": "taraflex", | ||
| "main": "index.js", | ||
| "license": "MIT", | ||
| "author": { | ||
| "name": "taraflex" | ||
| }, | ||
| "sideEffects": false, | ||
| "exports": { | ||
| ".": { | ||
| "require": "./dist/index.js", | ||
| "import": "./dist/index.mjs", | ||
| "types": "./dist/index.d.ts" | ||
| } | ||
| }, | ||
| "main": "./dist/index.js", | ||
| "module": "./dist/index.mjs", | ||
| "types": "./dist/index.d.ts", | ||
| "dependencies": { | ||
| "@taraflex/error": "~0.0.1" | ||
| }, | ||
| "engines": { | ||
| "node": ">=18.0.0" | ||
| }, | ||
| "scripts": { | ||
| "build": "tsc -p tsconfig.json", | ||
| "publish-library": "tsc -p tsconfig.json && npm publish --registry=https://registry.npmjs.org/ --access=public", | ||
| "test": "echo \"Error: no test specified\" && exit 1" | ||
| }, | ||
| "devDependencies": {} | ||
| "dev": "rollup -c ../../rollup.config.mjs --watch", | ||
| "dev:playground": "node ./dist/playground.mjs", | ||
| "prod": "rollup -c ../../rollup.config.mjs" | ||
| } | ||
| } |
-13
| export interface IDisposable { | ||
| dispose(): void; | ||
| } | ||
| export declare class CancelationTokenError extends Error { | ||
| } | ||
| export declare class CancelationToken { | ||
| private readonly connections; | ||
| private _canceled; | ||
| readonly canceled: boolean; | ||
| check(): void; | ||
| connect(cb: Function): IDisposable; | ||
| cancel(v?: any): void; | ||
| } |
-63
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| class CancelationTokenConnection { | ||
| constructor(connections, cb) { | ||
| this.connections = connections; | ||
| this.cb = cb; | ||
| connections.add(this); | ||
| } | ||
| run(v) { | ||
| try { | ||
| this.cb(v); | ||
| } | ||
| finally { | ||
| this.dispose(); | ||
| } | ||
| } | ||
| dispose() { | ||
| if (this.connections) { | ||
| this.connections.delete(this); | ||
| this.connections = null; | ||
| } | ||
| } | ||
| } | ||
| class CancelationTokenError extends Error { | ||
| } | ||
| exports.CancelationTokenError = CancelationTokenError; | ||
| class CancelationToken { | ||
| constructor() { | ||
| this.connections = new Set(); | ||
| this._canceled = false; | ||
| } | ||
| get canceled() { | ||
| return this._canceled; | ||
| } | ||
| check() { | ||
| if (this._canceled) { | ||
| throw new CancelationTokenError(); | ||
| } | ||
| } | ||
| connect(cb) { | ||
| this.check(); | ||
| return new CancelationTokenConnection(this.connections, cb); | ||
| } | ||
| cancel(v) { | ||
| if (!this._canceled) { | ||
| this._canceled = true; | ||
| let err = undefined; | ||
| this.connections.forEach(c => { | ||
| try { | ||
| c.run(v); | ||
| } | ||
| catch (e) { | ||
| err = e || err; | ||
| } | ||
| }); | ||
| this.connections.clear(); | ||
| if (err !== undefined) { | ||
| throw err; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| exports.CancelationToken = CancelationToken; |
| { | ||
| "compilerOptions": { | ||
| "alwaysStrict": true, | ||
| "module": "commonjs", | ||
| "moduleResolution": "node", | ||
| "target": "es6", | ||
| "sourceMap": false, | ||
| "noUnusedLocals": true, | ||
| "noUnusedParameters": true, | ||
| "removeComments": true, | ||
| "strictBindCallApply": true, | ||
| "declaration": true, | ||
| "lib": [ | ||
| "es6" | ||
| ] | ||
| }, | ||
| "files": [ | ||
| "index.ts" | ||
| ] | ||
| } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
12299
340.19%7
75%123
29.47%1
-50%1
Infinity%1
Infinity%+ Added
+ Added