@yume-chan/async
Advanced tools
Comparing version 2.2.0 to 4.0.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AsyncOperationManager = void 0; | ||
var promise_resolver_1 = require("./promise-resolver"); | ||
var AsyncOperationManager = (function () { | ||
function AsyncOperationManager(startId) { | ||
if (startId === void 0) { startId = 0; } | ||
this.pendingResolvers = new Map(); | ||
const promise_resolver_1 = require("./promise-resolver"); | ||
class AsyncOperationManager { | ||
nextId; | ||
pendingResolvers = new Map(); | ||
constructor(startId = 0) { | ||
this.nextId = startId; | ||
} | ||
AsyncOperationManager.prototype.add = function () { | ||
var id = this.nextId++; | ||
var resolver = new promise_resolver_1.PromiseResolver(); | ||
add() { | ||
const id = this.nextId++; | ||
const resolver = new promise_resolver_1.PromiseResolver(); | ||
this.pendingResolvers.set(id, resolver); | ||
return [id, resolver.promise]; | ||
}; | ||
AsyncOperationManager.prototype.getResolver = function (id) { | ||
} | ||
getResolver(id) { | ||
if (!this.pendingResolvers.has(id)) { | ||
return null; | ||
} | ||
var resolver = this.pendingResolvers.get(id); | ||
const resolver = this.pendingResolvers.get(id); | ||
this.pendingResolvers.delete(id); | ||
return resolver; | ||
}; | ||
AsyncOperationManager.prototype.resolve = function (id, result) { | ||
var resolver = this.getResolver(id); | ||
} | ||
resolve(id, result) { | ||
const resolver = this.getResolver(id); | ||
if (resolver !== null) { | ||
@@ -32,5 +32,5 @@ resolver.resolve(result); | ||
return false; | ||
}; | ||
AsyncOperationManager.prototype.reject = function (id, reason) { | ||
var resolver = this.getResolver(id); | ||
} | ||
reject(id, reason) { | ||
const resolver = this.getResolver(id); | ||
if (resolver !== null) { | ||
@@ -41,6 +41,5 @@ resolver.reject(reason); | ||
return false; | ||
}; | ||
return AsyncOperationManager; | ||
}()); | ||
} | ||
} | ||
exports.AsyncOperationManager = AsyncOperationManager; | ||
//# sourceMappingURL=async-operation-manager.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.delay = void 0; | ||
exports.delay = delay; | ||
function delay(time) { | ||
return new Promise(function (resolve) { | ||
globalThis.setTimeout(function () { return resolve(); }, time); | ||
return new Promise(resolve => { | ||
globalThis.setTimeout(() => resolve(), time); | ||
}); | ||
} | ||
exports.delay = delay; | ||
//# sourceMappingURL=delay.js.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./async-operation-manager"), exports); | ||
tslib_1.__exportStar(require("./delay"), exports); | ||
tslib_1.__exportStar(require("./promise-resolver"), exports); | ||
__exportStar(require("./async-operation-manager"), exports); | ||
__exportStar(require("./delay"), exports); | ||
__exportStar(require("./promise-resolver"), exports); | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PromiseResolver = void 0; | ||
var PromiseResolver = (function () { | ||
function PromiseResolver() { | ||
var _this = this; | ||
this._state = 'running'; | ||
this.resolve = function (value) { | ||
_this._resolve(value); | ||
_this._state = 'resolved'; | ||
}; | ||
this.reject = function (reason) { | ||
_this._reject(reason); | ||
_this._state = 'rejected'; | ||
}; | ||
this._promise = new Promise(function (resolve, reject) { | ||
_this._resolve = resolve; | ||
_this._reject = reject; | ||
class PromiseResolver { | ||
#promise; | ||
get promise() { return this.#promise; } | ||
#resolve; | ||
#reject; | ||
#state = 'running'; | ||
get state() { return this.#state; } | ||
constructor() { | ||
this.#promise = new Promise((resolve, reject) => { | ||
this.#resolve = resolve; | ||
this.#reject = reject; | ||
}); | ||
} | ||
Object.defineProperty(PromiseResolver.prototype, "promise", { | ||
get: function () { return this._promise; }, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(PromiseResolver.prototype, "state", { | ||
get: function () { return this._state; }, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
return PromiseResolver; | ||
}()); | ||
resolve = (value) => { | ||
this.#resolve(value); | ||
this.#state = 'resolved'; | ||
}; | ||
reject = (reason) => { | ||
this.#reject(reason); | ||
this.#state = 'rejected'; | ||
}; | ||
} | ||
exports.PromiseResolver = PromiseResolver; | ||
//# sourceMappingURL=promise-resolver.js.map |
@@ -0,0 +0,0 @@ export declare class AsyncOperationManager { |
export declare function delay(time: number): Promise<void>; | ||
//# sourceMappingURL=delay.d.ts.map |
@@ -0,0 +0,0 @@ export * from './async-operation-manager'; |
@@ -1,8 +0,5 @@ | ||
export declare type PromiseResolverState = 'running' | 'resolved' | 'rejected'; | ||
export type PromiseResolverState = 'running' | 'resolved' | 'rejected'; | ||
export declare class PromiseResolver<T> { | ||
private _promise; | ||
#private; | ||
get promise(): Promise<T>; | ||
private _resolve; | ||
private _reject; | ||
private _state; | ||
get state(): PromiseResolverState; | ||
@@ -9,0 +6,0 @@ constructor(); |
import { PromiseResolver } from "./promise-resolver"; | ||
var AsyncOperationManager = (function () { | ||
function AsyncOperationManager(startId) { | ||
if (startId === void 0) { startId = 0; } | ||
this.pendingResolvers = new Map(); | ||
export class AsyncOperationManager { | ||
nextId; | ||
pendingResolvers = new Map(); | ||
constructor(startId = 0) { | ||
this.nextId = startId; | ||
} | ||
AsyncOperationManager.prototype.add = function () { | ||
var id = this.nextId++; | ||
var resolver = new PromiseResolver(); | ||
add() { | ||
const id = this.nextId++; | ||
const resolver = new PromiseResolver(); | ||
this.pendingResolvers.set(id, resolver); | ||
return [id, resolver.promise]; | ||
}; | ||
AsyncOperationManager.prototype.getResolver = function (id) { | ||
} | ||
getResolver(id) { | ||
if (!this.pendingResolvers.has(id)) { | ||
return null; | ||
} | ||
var resolver = this.pendingResolvers.get(id); | ||
const resolver = this.pendingResolvers.get(id); | ||
this.pendingResolvers.delete(id); | ||
return resolver; | ||
}; | ||
AsyncOperationManager.prototype.resolve = function (id, result) { | ||
var resolver = this.getResolver(id); | ||
} | ||
resolve(id, result) { | ||
const resolver = this.getResolver(id); | ||
if (resolver !== null) { | ||
@@ -29,5 +29,5 @@ resolver.resolve(result); | ||
return false; | ||
}; | ||
AsyncOperationManager.prototype.reject = function (id, reason) { | ||
var resolver = this.getResolver(id); | ||
} | ||
reject(id, reason) { | ||
const resolver = this.getResolver(id); | ||
if (resolver !== null) { | ||
@@ -38,6 +38,4 @@ resolver.reject(reason); | ||
return false; | ||
}; | ||
return AsyncOperationManager; | ||
}()); | ||
export { AsyncOperationManager }; | ||
} | ||
} | ||
//# sourceMappingURL=async-operation-manager.js.map |
export function delay(time) { | ||
return new Promise(function (resolve) { | ||
globalThis.setTimeout(function () { return resolve(); }, time); | ||
return new Promise(resolve => { | ||
globalThis.setTimeout(() => resolve(), time); | ||
}); | ||
} | ||
//# sourceMappingURL=delay.js.map |
@@ -0,0 +0,0 @@ export * from './async-operation-manager'; |
@@ -1,31 +0,23 @@ | ||
var PromiseResolver = (function () { | ||
function PromiseResolver() { | ||
var _this = this; | ||
this._state = 'running'; | ||
this.resolve = function (value) { | ||
_this._resolve(value); | ||
_this._state = 'resolved'; | ||
}; | ||
this.reject = function (reason) { | ||
_this._reject(reason); | ||
_this._state = 'rejected'; | ||
}; | ||
this._promise = new Promise(function (resolve, reject) { | ||
_this._resolve = resolve; | ||
_this._reject = reject; | ||
export class PromiseResolver { | ||
#promise; | ||
get promise() { return this.#promise; } | ||
#resolve; | ||
#reject; | ||
#state = 'running'; | ||
get state() { return this.#state; } | ||
constructor() { | ||
this.#promise = new Promise((resolve, reject) => { | ||
this.#resolve = resolve; | ||
this.#reject = reject; | ||
}); | ||
} | ||
Object.defineProperty(PromiseResolver.prototype, "promise", { | ||
get: function () { return this._promise; }, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(PromiseResolver.prototype, "state", { | ||
get: function () { return this._state; }, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
return PromiseResolver; | ||
}()); | ||
export { PromiseResolver }; | ||
resolve = (value) => { | ||
this.#resolve(value); | ||
this.#state = 'resolved'; | ||
}; | ||
reject = (reason) => { | ||
this.#reject(reason); | ||
this.#state = 'rejected'; | ||
}; | ||
} | ||
//# sourceMappingURL=promise-resolver.js.map |
{ | ||
"name": "@yume-chan/async", | ||
"version": "2.2.0", | ||
"description": "Utils for async programming.", | ||
"keywords": [ | ||
"async", | ||
"util" | ||
], | ||
"license": "MIT", | ||
"author": { | ||
"name": "Simon Chan", | ||
"email": "cnsimonchan@live.com", | ||
"url": "https://chensi.moe/blog" | ||
}, | ||
"homepage": "https://github.com/yume-chan/async#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/yume-chan/async.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/yume-chan/async/issues" | ||
}, | ||
"main": "cjs/index.js", | ||
"module": "esm/index.js", | ||
"types": "dts/index.d.ts", | ||
"scripts": { | ||
"build": "rimraf {cjs,esm,dts} && tsc -b tsconfig.esm.json tsconfig.cjs.json", | ||
"test": "jest", | ||
"coverage": "jest --coverage", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"dependencies": { | ||
"tslib": "^2.3.1" | ||
}, | ||
"devDependencies": { | ||
"@jest/globals": "^28.1.0", | ||
"jest": "^28.1.0", | ||
"rimraf": "3.0.2", | ||
"ts-jest": "^28.0.2", | ||
"typescript": "^4.7.2" | ||
} | ||
} | ||
"name": "@yume-chan/async", | ||
"version": "4.0.0", | ||
"description": "Utils for async programming.", | ||
"keywords": [ | ||
"async", | ||
"util" | ||
], | ||
"license": "MIT", | ||
"author": { | ||
"name": "Simon Chan", | ||
"email": "cnsimonchan@live.com", | ||
"url": "https://chensi.moe/blog" | ||
}, | ||
"homepage": "https://github.com/yume-chan/async#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/yume-chan/async.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/yume-chan/async/issues" | ||
}, | ||
"main": "cjs/index.js", | ||
"module": "esm/index.js", | ||
"types": "dts/index.d.ts", | ||
"devDependencies": { | ||
"@jest/globals": "^29.7.0", | ||
"jest": "^29.7.0", | ||
"rimraf": "6.0.1", | ||
"ts-jest": "^29.2.5", | ||
"typescript": "^5.6.3" | ||
}, | ||
"scripts": { | ||
"build": "rimraf --glob {cjs,esm,dts} *.tsbuildinfo && tsc -b tsconfig.esm.json tsconfig.cjs.json", | ||
"test": "jest", | ||
"coverage": "jest --coverage" | ||
} | ||
} |
export type PromiseResolverState = 'running' | 'resolved' | 'rejected'; | ||
export class PromiseResolver<T> { | ||
private _promise: Promise<T>; | ||
public get promise(): Promise<T> { return this._promise; } | ||
#promise: Promise<T>; | ||
public get promise(): Promise<T> { return this.#promise; } | ||
private _resolve!: (value: T | PromiseLike<T>) => void; | ||
private _reject!: (reason?: any) => void; | ||
#resolve!: (value: T | PromiseLike<T>) => void; | ||
#reject!: (reason?: any) => void; | ||
private _state: PromiseResolverState = 'running'; | ||
public get state(): PromiseResolverState { return this._state; } | ||
#state: PromiseResolverState = 'running'; | ||
public get state(): PromiseResolverState { return this.#state; } | ||
public constructor() { | ||
this._promise = new Promise<T>((resolve, reject) => { | ||
this._resolve = resolve; | ||
this._reject = reject; | ||
this.#promise = new Promise<T>((resolve, reject) => { | ||
this.#resolve = resolve; | ||
this.#reject = reject; | ||
}); | ||
@@ -21,10 +21,10 @@ } | ||
public resolve = (value: T | PromiseLike<T>): void => { | ||
this._resolve(value); | ||
this._state = 'resolved'; | ||
this.#resolve(value); | ||
this.#state = 'resolved'; | ||
}; | ||
public reject = (reason?: any): void => { | ||
this._reject(reason); | ||
this._state = 'rejected'; | ||
this.#reject(reason); | ||
this.#state = 'rejected'; | ||
}; | ||
} |
{ | ||
"compilerOptions": { | ||
/* Basic Options */ | ||
"target": "ES5", // /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ | ||
"target": "ESNext", // /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ | ||
"module": "ESNext", // /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ | ||
@@ -18,3 +18,3 @@ "lib": [ // /* Specify library files to be included in the compilation. */ | ||
// "noEmit": true, /* Do not emit outputs. */ | ||
"importHelpers": true, // /* Import emit helpers from 'tslib'. */ | ||
"importHelpers": false, // /* Import emit helpers from 'tslib'. */ | ||
"downlevelIteration": true, // /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ | ||
@@ -21,0 +21,0 @@ "isolatedModules": true, // /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
0
36
23730
312
- Removedtslib@^2.3.1
- Removedtslib@2.8.1(transitive)