@matrixai/async-init
Advanced tools
Comparing version 1.9.4 to 1.10.0
import type { Status, Class } from './types'; | ||
import { Evented } from '@matrixai/events'; | ||
import { RWLockWriter } from '@matrixai/async-locks'; | ||
import { destroyed, status, initLock } from './utils'; | ||
import { destroyed, status, statusP, initLock } from './utils'; | ||
interface CreateDestroy<DestroyReturn = unknown> extends Evented { | ||
get [destroyed](): boolean; | ||
get [status](): Status; | ||
get [statusP](): Promise<Status>; | ||
readonly [initLock]: RWLockWriter; | ||
@@ -18,2 +19,2 @@ destroy(...args: Array<any>): Promise<DestroyReturn | void>; | ||
declare function ready(errorDestroyed?: Error, block?: boolean, allowedStatuses?: Array<Status>): (target: any, key: string, descriptor: PropertyDescriptor) => PropertyDescriptor; | ||
export { CreateDestroy, ready, destroyed, status, initLock }; | ||
export { CreateDestroy, ready, destroyed, status, statusP, initLock }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.initLock = exports.status = exports.destroyed = exports.ready = exports.CreateDestroy = void 0; | ||
exports.initLock = exports.statusP = exports.status = exports.destroyed = exports.ready = exports.CreateDestroy = void 0; | ||
const events_1 = require("@matrixai/events"); | ||
@@ -9,2 +9,3 @@ const async_locks_1 = require("@matrixai/async-locks"); | ||
Object.defineProperty(exports, "status", { enumerable: true, get: function () { return utils_1.status; } }); | ||
Object.defineProperty(exports, "statusP", { enumerable: true, get: function () { return utils_1.statusP; } }); | ||
Object.defineProperty(exports, "initLock", { enumerable: true, get: function () { return utils_1.initLock; } }); | ||
@@ -15,5 +16,8 @@ const events_2 = require("./events"); | ||
return (constructor) => { | ||
const { p, resolveP } = (0, utils_1.promise)(); | ||
const constructor_ = class extends (0, events_1.Evented)()(constructor) { | ||
[utils_1._destroyed] = false; | ||
[utils_1._status] = null; | ||
[utils_1._statusP] = p; | ||
[utils_1.resolveStatusP] = resolveP; | ||
[utils_1.initLock] = new async_locks_1.RWLockWriter(); | ||
@@ -26,21 +30,31 @@ get [utils_1.destroyed]() { | ||
} | ||
get [utils_1.statusP]() { | ||
return this[utils_1._statusP]; | ||
} | ||
async destroy(...args) { | ||
return this[utils_1.initLock].withWriteF(async () => { | ||
return this[utils_1.initLock] | ||
.withWriteF(async () => { | ||
if (this[utils_1._destroyed]) { | ||
return; | ||
} | ||
this[utils_1._status] = 'destroying'; | ||
try { | ||
if (this[utils_1._destroyed]) { | ||
return; | ||
} | ||
this.dispatchEvent(new eventDestroy()); | ||
let result; | ||
if (typeof super['destroy'] === 'function') { | ||
result = await super.destroy(...args); | ||
} | ||
this[utils_1._destroyed] = true; | ||
this.dispatchEvent(new eventDestroyed()); | ||
return result; | ||
this[utils_1.resolveStatusP]('destroying'); | ||
const { p, resolveP } = (0, utils_1.promise)(); | ||
this[utils_1._statusP] = p; | ||
this[utils_1.resolveStatusP] = resolveP; | ||
this.dispatchEvent(new eventDestroy()); | ||
let result; | ||
if (typeof super['destroy'] === 'function') { | ||
result = await super.destroy(...args); | ||
} | ||
finally { | ||
this[utils_1._status] = null; | ||
} | ||
this[utils_1._destroyed] = true; | ||
this.dispatchEvent(new eventDestroyed()); | ||
return result; | ||
}) | ||
.finally(() => { | ||
this[utils_1._status] = null; | ||
this[utils_1.resolveStatusP](null); | ||
const { p, resolveP } = (0, utils_1.promise)(); | ||
this[utils_1._statusP] = p; | ||
this[utils_1.resolveStatusP] = resolveP; | ||
}); | ||
@@ -73,2 +87,7 @@ } | ||
descriptor[kind] = async function (...args) { | ||
// If it is write locked, wait until the status has changed | ||
// This method may be called in between write locked and status change | ||
if (this[utils_1.initLock].isLocked('write') && this[utils_1._status] === null) { | ||
await this[utils_1._statusP]; | ||
} | ||
if (allowedStatuses.includes(this[utils_1._status])) { | ||
@@ -100,3 +119,4 @@ return f.apply(this, args); | ||
} | ||
if (this[utils_1.initLock].isLocked('write') || this[utils_1._destroyed]) { | ||
if ((this[utils_1.initLock].isLocked('write') && this[utils_1.status] !== null) || | ||
this[utils_1._destroyed]) { | ||
(0, utils_1.resetStackTrace)(errorDestroyed, descriptor[kind]); | ||
@@ -110,2 +130,7 @@ throw errorDestroyed; | ||
descriptor[kind] = async function* (...args) { | ||
// If it is write locked, wait until the status has changed | ||
// This method may be called in between write locked and status change | ||
if (this[utils_1.initLock].isLocked('write') && this[utils_1._status] === null) { | ||
await this[utils_1._statusP]; | ||
} | ||
if (allowedStatuses.includes(this[utils_1._status])) { | ||
@@ -137,3 +162,4 @@ return yield* f.apply(this, args); | ||
} | ||
if (this[utils_1.initLock].isLocked('write') || this[utils_1._destroyed]) { | ||
if ((this[utils_1.initLock].isLocked('write') && this[utils_1.status] !== null) || | ||
this[utils_1._destroyed]) { | ||
(0, utils_1.resetStackTrace)(errorDestroyed, descriptor[kind]); | ||
@@ -140,0 +166,0 @@ throw errorDestroyed; |
import type { Status, Class } from './types'; | ||
import { Evented } from '@matrixai/events'; | ||
import { RWLockWriter } from '@matrixai/async-locks'; | ||
import { running, destroyed, status, initLock } from './utils'; | ||
import { running, destroyed, status, statusP, initLock } from './utils'; | ||
interface CreateDestroyStartStop<StartReturn = unknown, StopReturn = unknown, DestroyReturn = unknown> extends Evented { | ||
@@ -9,2 +9,3 @@ get [running](): boolean; | ||
get [status](): Status; | ||
get [statusP](): Promise<Status>; | ||
readonly [initLock]: RWLockWriter; | ||
@@ -28,2 +29,2 @@ start(...args: Array<any>): Promise<StartReturn | void>; | ||
declare function ready(errorNotRunning?: Error, block?: boolean, allowedStatuses?: Array<Status>): (target: any, key: string, descriptor: PropertyDescriptor) => PropertyDescriptor; | ||
export { CreateDestroyStartStop, ready, running, destroyed, status, initLock }; | ||
export { CreateDestroyStartStop, ready, running, destroyed, status, statusP, initLock, }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.initLock = exports.status = exports.destroyed = exports.running = exports.ready = exports.CreateDestroyStartStop = void 0; | ||
exports.initLock = exports.statusP = exports.status = exports.destroyed = exports.running = exports.ready = exports.CreateDestroyStartStop = void 0; | ||
const events_1 = require("@matrixai/events"); | ||
@@ -10,2 +10,3 @@ const async_locks_1 = require("@matrixai/async-locks"); | ||
Object.defineProperty(exports, "status", { enumerable: true, get: function () { return utils_1.status; } }); | ||
Object.defineProperty(exports, "statusP", { enumerable: true, get: function () { return utils_1.statusP; } }); | ||
Object.defineProperty(exports, "initLock", { enumerable: true, get: function () { return utils_1.initLock; } }); | ||
@@ -16,2 +17,3 @@ const events_2 = require("./events"); | ||
return (constructor) => { | ||
const { p, resolveP } = (0, utils_1.promise)(); | ||
const constructor_ = class extends (0, events_1.Evented)()(constructor) { | ||
@@ -21,2 +23,4 @@ [utils_1._running] = false; | ||
[utils_1._status] = null; | ||
[utils_1._statusP] = p; | ||
[utils_1.resolveStatusP] = resolveP; | ||
[utils_1.initLock] = new async_locks_1.RWLockWriter(); | ||
@@ -32,80 +36,104 @@ get [utils_1.running]() { | ||
} | ||
get [utils_1.statusP]() { | ||
return this[utils_1._statusP]; | ||
} | ||
async destroy(...args) { | ||
return this[utils_1.initLock].withWriteF(async () => { | ||
return this[utils_1.initLock] | ||
.withWriteF(async () => { | ||
if (this[utils_1._destroyed]) { | ||
return; | ||
} | ||
if (this[utils_1._running]) { | ||
// Unfortunately `this.destroy` doesn't work as the decorated function | ||
(0, utils_1.resetStackTrace)(errorRunning); | ||
throw errorRunning; | ||
} | ||
this[utils_1._status] = 'destroying'; | ||
try { | ||
if (this[utils_1._destroyed]) { | ||
return; | ||
} | ||
if (this[utils_1._running]) { | ||
// Unfortunately `this.destroy` doesn't work as the decorated function | ||
(0, utils_1.resetStackTrace)(errorRunning); | ||
throw errorRunning; | ||
} | ||
this.dispatchEvent(new eventDestroy()); | ||
let result; | ||
if (typeof super['destroy'] === 'function') { | ||
result = await super.destroy(...args); | ||
} | ||
this[utils_1._destroyed] = true; | ||
this.dispatchEvent(new eventDestroyed()); | ||
return result; | ||
this[utils_1.resolveStatusP]('destroying'); | ||
const { p, resolveP } = (0, utils_1.promise)(); | ||
this[utils_1._statusP] = p; | ||
this[utils_1.resolveStatusP] = resolveP; | ||
this.dispatchEvent(new eventDestroy()); | ||
let result; | ||
if (typeof super['destroy'] === 'function') { | ||
result = await super.destroy(...args); | ||
} | ||
finally { | ||
this[utils_1._status] = null; | ||
} | ||
this[utils_1._destroyed] = true; | ||
this.dispatchEvent(new eventDestroyed()); | ||
return result; | ||
}) | ||
.finally(() => { | ||
this[utils_1._status] = null; | ||
this[utils_1.resolveStatusP](null); | ||
const { p, resolveP } = (0, utils_1.promise)(); | ||
this[utils_1._statusP] = p; | ||
this[utils_1.resolveStatusP] = resolveP; | ||
}); | ||
} | ||
async start(...args) { | ||
return this[utils_1.initLock].withWriteF(async () => { | ||
return this[utils_1.initLock] | ||
.withWriteF(async () => { | ||
if (this[utils_1._running]) { | ||
return; | ||
} | ||
if (this[utils_1._destroyed]) { | ||
// Unfortunately `this.start` doesn't work as the decorated function | ||
(0, utils_1.resetStackTrace)(errorDestroyed); | ||
throw errorDestroyed; | ||
} | ||
this[utils_1._status] = 'starting'; | ||
try { | ||
if (this[utils_1._running]) { | ||
return; | ||
} | ||
if (this[utils_1._destroyed]) { | ||
// Unfortunately `this.start` doesn't work as the decorated function | ||
(0, utils_1.resetStackTrace)(errorDestroyed); | ||
throw errorDestroyed; | ||
} | ||
this.dispatchEvent(new eventStart()); | ||
let result; | ||
if (typeof super['start'] === 'function') { | ||
result = await super.start(...args); | ||
} | ||
this[utils_1._running] = true; | ||
this.dispatchEvent(new eventStarted()); | ||
return result; | ||
this[utils_1.resolveStatusP]('starting'); | ||
const { p, resolveP } = (0, utils_1.promise)(); | ||
this[utils_1._statusP] = p; | ||
this[utils_1.resolveStatusP] = resolveP; | ||
this.dispatchEvent(new eventStart()); | ||
let result; | ||
if (typeof super['start'] === 'function') { | ||
result = await super.start(...args); | ||
} | ||
finally { | ||
this[utils_1._status] = null; | ||
} | ||
this[utils_1._running] = true; | ||
this.dispatchEvent(new eventStarted()); | ||
return result; | ||
}) | ||
.finally(() => { | ||
this[utils_1._status] = null; | ||
this[utils_1.resolveStatusP](null); | ||
const { p, resolveP } = (0, utils_1.promise)(); | ||
this[utils_1._statusP] = p; | ||
this[utils_1.resolveStatusP] = resolveP; | ||
}); | ||
} | ||
async stop(...args) { | ||
return this[utils_1.initLock].withWriteF(async () => { | ||
return this[utils_1.initLock] | ||
.withWriteF(async () => { | ||
if (!this[utils_1._running]) { | ||
return; | ||
} | ||
if (this[utils_1._destroyed]) { | ||
// It is not possible to be running and destroyed | ||
// however this line is here for completion | ||
// Unfortunately `this.stop` doesn't work as the decorated function | ||
(0, utils_1.resetStackTrace)(errorDestroyed); | ||
throw errorDestroyed; | ||
} | ||
this[utils_1._status] = 'stopping'; | ||
try { | ||
if (!this[utils_1._running]) { | ||
return; | ||
} | ||
if (this[utils_1._destroyed]) { | ||
// It is not possible to be running and destroyed | ||
// however this line is here for completion | ||
// Unfortunately `this.stop` doesn't work as the decorated function | ||
(0, utils_1.resetStackTrace)(errorDestroyed); | ||
throw errorDestroyed; | ||
} | ||
this.dispatchEvent(new eventStop()); | ||
let result; | ||
if (typeof super['stop'] === 'function') { | ||
result = await super.stop(...args); | ||
} | ||
this[utils_1._running] = false; | ||
this.dispatchEvent(new eventStopped()); | ||
return result; | ||
this[utils_1.resolveStatusP]('stopping'); | ||
const { p, resolveP } = (0, utils_1.promise)(); | ||
this[utils_1._statusP] = p; | ||
this[utils_1.resolveStatusP] = resolveP; | ||
this.dispatchEvent(new eventStop()); | ||
let result; | ||
if (typeof super['stop'] === 'function') { | ||
result = await super.stop(...args); | ||
} | ||
finally { | ||
this[utils_1._status] = null; | ||
} | ||
this[utils_1._running] = false; | ||
this.dispatchEvent(new eventStopped()); | ||
return result; | ||
}) | ||
.finally(() => { | ||
this[utils_1._status] = null; | ||
this[utils_1.resolveStatusP](null); | ||
const { p, resolveP } = (0, utils_1.promise)(); | ||
this[utils_1._statusP] = p; | ||
this[utils_1.resolveStatusP] = resolveP; | ||
}); | ||
@@ -138,2 +166,7 @@ } | ||
descriptor[kind] = async function (...args) { | ||
// If it is write locked, wait until the status has changed | ||
// This method may be called in between write locked and status change | ||
if (this[utils_1.initLock].isLocked('write') && this[utils_1._status] === null) { | ||
await this[utils_1._statusP]; | ||
} | ||
if (allowedStatuses.includes(this[utils_1._status])) { | ||
@@ -165,3 +198,4 @@ return f.apply(this, args); | ||
} | ||
if (this[utils_1.initLock].isLocked('write') || !this[utils_1._running]) { | ||
if ((this[utils_1.initLock].isLocked('write') && this[utils_1.status] !== null) || | ||
!this[utils_1._running]) { | ||
(0, utils_1.resetStackTrace)(errorNotRunning, descriptor[kind]); | ||
@@ -175,2 +209,7 @@ throw errorNotRunning; | ||
descriptor[kind] = async function* (...args) { | ||
// If it is write locked, wait until the status has changed | ||
// This method may be called in between write locked and status change | ||
if (this[utils_1.initLock].isLocked('write') && this[utils_1._status] === null) { | ||
await this[utils_1._statusP]; | ||
} | ||
if (allowedStatuses.includes(this[utils_1._status])) { | ||
@@ -202,3 +241,4 @@ return yield* f.apply(this, args); | ||
} | ||
if (this[utils_1.initLock].isLocked('write') || !this[utils_1._running]) { | ||
if ((this[utils_1.initLock].isLocked('write') && this[utils_1.status] !== null) || | ||
!this[utils_1._running]) { | ||
(0, utils_1.resetStackTrace)(errorNotRunning, descriptor[kind]); | ||
@@ -205,0 +245,0 @@ throw errorNotRunning; |
@@ -7,2 +7,2 @@ export * as types from './types'; | ||
export * as errors from './errors'; | ||
export { running, destroyed, status, initLock } from './utils'; | ||
export { running, destroyed, status, statusP, initLock } from './utils'; |
@@ -26,3 +26,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.initLock = exports.status = exports.destroyed = exports.running = exports.errors = exports.events = exports.startStop = exports.createDestroy = exports.createDestroyStartStop = exports.types = void 0; | ||
exports.initLock = exports.statusP = exports.status = exports.destroyed = exports.running = exports.errors = exports.events = exports.startStop = exports.createDestroy = exports.createDestroyStartStop = exports.types = void 0; | ||
exports.types = __importStar(require("./types")); | ||
@@ -38,3 +38,4 @@ exports.createDestroyStartStop = __importStar(require("./CreateDestroyStartStop")); | ||
Object.defineProperty(exports, "status", { enumerable: true, get: function () { return utils_1.status; } }); | ||
Object.defineProperty(exports, "statusP", { enumerable: true, get: function () { return utils_1.statusP; } }); | ||
Object.defineProperty(exports, "initLock", { enumerable: true, get: function () { return utils_1.initLock; } }); | ||
//# sourceMappingURL=index.js.map |
import type { Status, Class } from './types'; | ||
import { Evented } from '@matrixai/events'; | ||
import { RWLockWriter } from '@matrixai/async-locks'; | ||
import { running, status, initLock } from './utils'; | ||
import { running, status, statusP, initLock } from './utils'; | ||
interface StartStop<StartReturn = unknown, StopReturn = unknown> extends Evented { | ||
get [running](): boolean; | ||
get [status](): Status; | ||
get [statusP](): Promise<Status>; | ||
readonly [initLock]: RWLockWriter; | ||
@@ -22,2 +23,2 @@ start(...args: Array<any>): Promise<StartReturn | void>; | ||
declare function ready(errorNotRunning?: Error, block?: boolean, allowedStatuses?: Array<Status>): (target: any, key: string, descriptor: PropertyDescriptor) => PropertyDescriptor; | ||
export { StartStop, ready, running, status, initLock }; | ||
export { StartStop, ready, running, status, statusP, initLock }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.initLock = exports.status = exports.running = exports.ready = exports.StartStop = void 0; | ||
exports.initLock = exports.statusP = exports.status = exports.running = exports.ready = exports.StartStop = void 0; | ||
const events_1 = require("@matrixai/events"); | ||
@@ -9,2 +9,3 @@ const async_locks_1 = require("@matrixai/async-locks"); | ||
Object.defineProperty(exports, "status", { enumerable: true, get: function () { return utils_1.status; } }); | ||
Object.defineProperty(exports, "statusP", { enumerable: true, get: function () { return utils_1.statusP; } }); | ||
Object.defineProperty(exports, "initLock", { enumerable: true, get: function () { return utils_1.initLock; } }); | ||
@@ -15,5 +16,8 @@ const events_2 = require("./events"); | ||
return (constructor) => { | ||
const { p, resolveP } = (0, utils_1.promise)(); | ||
const constructor_ = class extends (0, events_1.Evented)()(constructor) { | ||
[utils_1._running] = false; | ||
[utils_1._status] = null; | ||
[utils_1._statusP] = p; | ||
[utils_1.resolveStatusP] = resolveP; | ||
[utils_1.initLock] = new async_locks_1.RWLockWriter(); | ||
@@ -26,42 +30,59 @@ get [utils_1.running]() { | ||
} | ||
get [utils_1.statusP]() { | ||
return this[utils_1._statusP]; | ||
} | ||
async start(...args) { | ||
return this[utils_1.initLock].withWriteF(async () => { | ||
return this[utils_1.initLock] | ||
.withWriteF(async () => { | ||
if (this[utils_1._running]) { | ||
return; | ||
} | ||
this[utils_1._status] = 'starting'; | ||
try { | ||
if (this[utils_1._running]) { | ||
return; | ||
} | ||
this.dispatchEvent(new eventStart()); | ||
let result; | ||
if (typeof super['start'] === 'function') { | ||
result = await super.start(...args); | ||
} | ||
this[utils_1._running] = true; | ||
this.dispatchEvent(new eventStarted()); | ||
return result; | ||
this[utils_1.resolveStatusP]('starting'); | ||
const { p, resolveP } = (0, utils_1.promise)(); | ||
this[utils_1._statusP] = p; | ||
this[utils_1.resolveStatusP] = resolveP; | ||
this.dispatchEvent(new eventStart()); | ||
let result; | ||
if (typeof super['start'] === 'function') { | ||
result = await super.start(...args); | ||
} | ||
finally { | ||
this[utils_1._status] = null; | ||
} | ||
this[utils_1._running] = true; | ||
this.dispatchEvent(new eventStarted()); | ||
return result; | ||
}) | ||
.finally(() => { | ||
this[utils_1._status] = null; | ||
this[utils_1.resolveStatusP](null); | ||
const { p, resolveP } = (0, utils_1.promise)(); | ||
this[utils_1._statusP] = p; | ||
this[utils_1.resolveStatusP] = resolveP; | ||
}); | ||
} | ||
async stop(...args) { | ||
return this[utils_1.initLock].withWriteF(async () => { | ||
return this[utils_1.initLock] | ||
.withWriteF(async () => { | ||
if (!this[utils_1._running]) { | ||
return; | ||
} | ||
this[utils_1._status] = 'stopping'; | ||
try { | ||
if (!this[utils_1._running]) { | ||
return; | ||
} | ||
this.dispatchEvent(new eventStop()); | ||
let result; | ||
if (typeof super['stop'] === 'function') { | ||
result = await super.stop(...args); | ||
} | ||
this[utils_1._running] = false; | ||
this.dispatchEvent(new eventStopped()); | ||
return result; | ||
this[utils_1.resolveStatusP]('stopping'); | ||
const { p, resolveP } = (0, utils_1.promise)(); | ||
this[utils_1._statusP] = p; | ||
this[utils_1.resolveStatusP] = resolveP; | ||
this.dispatchEvent(new eventStop()); | ||
let result; | ||
if (typeof super['stop'] === 'function') { | ||
result = await super.stop(...args); | ||
} | ||
finally { | ||
this[utils_1._status] = null; | ||
} | ||
this[utils_1._running] = false; | ||
this.dispatchEvent(new eventStopped()); | ||
return result; | ||
}) | ||
.finally(() => { | ||
this[utils_1._status] = null; | ||
this[utils_1.resolveStatusP](null); | ||
const { p, resolveP } = (0, utils_1.promise)(); | ||
this[utils_1._statusP] = p; | ||
this[utils_1.resolveStatusP] = resolveP; | ||
}); | ||
@@ -94,2 +115,7 @@ } | ||
descriptor[kind] = async function (...args) { | ||
// If it is write locked, wait until the status has changed | ||
// This method may be called in between write locked and status change | ||
if (this[utils_1.initLock].isLocked('write') && this[utils_1._status] === null) { | ||
await this[utils_1._statusP]; | ||
} | ||
if (allowedStatuses.includes(this[utils_1._status])) { | ||
@@ -121,3 +147,4 @@ return f.apply(this, args); | ||
} | ||
if (this[utils_1.initLock].isLocked('write') || !this[utils_1._running]) { | ||
if ((this[utils_1.initLock].isLocked('write') && this[utils_1.status] !== null) || | ||
!this[utils_1._running]) { | ||
(0, utils_1.resetStackTrace)(errorNotRunning, descriptor[kind]); | ||
@@ -131,2 +158,7 @@ throw errorNotRunning; | ||
descriptor[kind] = async function* (...args) { | ||
// If it is write locked, wait until the status has changed | ||
// This method may be called in between write locked and status change | ||
if (this[utils_1.initLock].isLocked('write') && this[utils_1._status] === null) { | ||
await this[utils_1._statusP]; | ||
} | ||
if (allowedStatuses.includes(this[utils_1._status])) { | ||
@@ -158,3 +190,4 @@ return yield* f.apply(this, args); | ||
} | ||
if (this[utils_1.initLock].isLocked('write') || !this[utils_1._running]) { | ||
if ((this[utils_1.initLock].isLocked('write') && this[utils_1.status] !== null) || | ||
!this[utils_1._running]) { | ||
(0, utils_1.resetStackTrace)(errorNotRunning, descriptor[kind]); | ||
@@ -161,0 +194,0 @@ throw errorNotRunning; |
@@ -0,3 +1,11 @@ | ||
/** | ||
* Deconstructed promise | ||
*/ | ||
type PromiseDeconstructed<T> = { | ||
p: Promise<T>; | ||
resolveP: (value: T | PromiseLike<T>) => void; | ||
rejectP: (reason?: any) => void; | ||
}; | ||
type Status = 'destroying' | 'starting' | 'stopping' | null; | ||
type Class<T> = new (...args: any[]) => T; | ||
export type { Status, Class }; | ||
export type { PromiseDeconstructed, Status, Class }; |
@@ -0,1 +1,2 @@ | ||
import type { PromiseDeconstructed } from './types'; | ||
/** | ||
@@ -10,2 +11,5 @@ * Symbols prevents name clashes with decorated classes | ||
declare const status: unique symbol; | ||
declare const _statusP: unique symbol; | ||
declare const statusP: unique symbol; | ||
declare const resolveStatusP: unique symbol; | ||
declare const initLock: unique symbol; | ||
@@ -17,2 +21,6 @@ declare const AsyncFunction: Function; | ||
/** | ||
* Deconstructed promise | ||
*/ | ||
declare function promise<T = void>(): PromiseDeconstructed<T>; | ||
/** | ||
* Ready wrappers take exception objects | ||
@@ -24,2 +32,2 @@ * JS exception traces are created when the exception is instantiated | ||
declare function resetStackTrace(error: Error, decorated?: Function): void; | ||
export { _running, running, _destroyed, destroyed, _status, status, initLock, AsyncFunction, GeneratorFunction, AsyncGeneratorFunction, hasCaptureStackTrace, resetStackTrace, }; | ||
export { _running, running, _destroyed, destroyed, _status, status, _statusP, statusP, resolveStatusP, initLock, AsyncFunction, GeneratorFunction, AsyncGeneratorFunction, hasCaptureStackTrace, promise, resetStackTrace, }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resetStackTrace = exports.hasCaptureStackTrace = exports.AsyncGeneratorFunction = exports.GeneratorFunction = exports.AsyncFunction = exports.initLock = exports.status = exports._status = exports.destroyed = exports._destroyed = exports.running = exports._running = void 0; | ||
exports.resetStackTrace = exports.promise = exports.hasCaptureStackTrace = exports.AsyncGeneratorFunction = exports.GeneratorFunction = exports.AsyncFunction = exports.initLock = exports.resolveStatusP = exports.statusP = exports._statusP = exports.status = exports._status = exports.destroyed = exports._destroyed = exports.running = exports._running = void 0; | ||
/** | ||
@@ -19,2 +19,8 @@ * Symbols prevents name clashes with decorated classes | ||
exports.status = status; | ||
const _statusP = Symbol('_statusP'); | ||
exports._statusP = _statusP; | ||
const statusP = Symbol('statusP'); | ||
exports.statusP = statusP; | ||
const resolveStatusP = Symbol('resolveStatusP'); | ||
exports.resolveStatusP = resolveStatusP; | ||
const initLock = Symbol('initLock'); | ||
@@ -31,2 +37,18 @@ exports.initLock = initLock; | ||
/** | ||
* Deconstructed promise | ||
*/ | ||
function promise() { | ||
let resolveP, rejectP; | ||
const p = new Promise((resolve, reject) => { | ||
resolveP = resolve; | ||
rejectP = reject; | ||
}); | ||
return { | ||
p, | ||
resolveP, | ||
rejectP, | ||
}; | ||
} | ||
exports.promise = promise; | ||
/** | ||
* Ready wrappers take exception objects | ||
@@ -33,0 +55,0 @@ * JS exception traces are created when the exception is instantiated |
{ | ||
"name": "@matrixai/async-init", | ||
"version": "1.9.4", | ||
"version": "1.10.0", | ||
"author": "Roger Qiu", | ||
@@ -5,0 +5,0 @@ "description": "Asynchronous Initialisation and Deinitialisation Decorators", |
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
85346
922