@bunt/unit
Advanced tools
Comparing version 0.18.0 to 0.18.1
@@ -6,2 +6,13 @@ # Change Log | ||
## [0.18.1](https://github.com/izatop/bunt/compare/v0.18.0...v0.18.1) (2021-05-24) | ||
### Bug Fixes | ||
* disposer ([63f9af1](https://github.com/izatop/bunt/commit/63f9af19640a0ded4ae29e956c04e4de90b3b96f)) | ||
# [0.18.0](https://github.com/izatop/bunt/compare/v0.17.0...v0.18.0) (2021-05-24) | ||
@@ -8,0 +19,0 @@ |
@@ -16,13 +16,13 @@ "use strict"; | ||
static resolve(target) { | ||
var _a; | ||
const disposer = (_a = collection.get(target)) !== null && _a !== void 0 ? _a : new Disposer_1.Disposer(target.constructor.name); | ||
if (!collection.has(target)) { | ||
const dispose = target.dispose; | ||
disposer.attach(() => dispose.call(this)); | ||
const disposer = collection.get(target); | ||
if (!disposer) { | ||
const finish = target.dispose; | ||
const newDisposer = new Disposer_1.Disposer(target.constructor.name, () => finish.call(this)); | ||
Reflect.defineProperty(target, "dispose", { | ||
value: function () { | ||
return disposer.dispose(); | ||
return newDisposer.dispose(); | ||
}, | ||
}); | ||
collection.set(target, disposer); | ||
collection.set(target, newDisposer); | ||
return newDisposer; | ||
} | ||
@@ -29,0 +29,0 @@ return disposer; |
import { Logger } from "@bunt/util"; | ||
import { DisposableType, IDisposedHistory } from "../Runtime"; | ||
import { DisposableFn, DisposableType, IDisposedHistory } from "../Runtime"; | ||
export declare class Disposer { | ||
#private; | ||
protected readonly logger: Logger; | ||
constructor(label: string); | ||
constructor(label: string, finish: DisposableFn); | ||
get disposed(): boolean; | ||
@@ -8,0 +8,0 @@ get history(): IDisposedHistory[]; |
@@ -8,8 +8,2 @@ "use strict"; | ||
}; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
}; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { | ||
@@ -22,3 +16,9 @@ if (!privateMap.has(receiver)) { | ||
}; | ||
var _disposable, _disposeHistory, _state; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
}; | ||
var _disposable, _disposeHistory, _finish, _state; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -29,7 +29,9 @@ exports.Disposer = void 0; | ||
class Disposer { | ||
constructor(label) { | ||
constructor(label, finish) { | ||
_disposable.set(this, []); | ||
_disposeHistory.set(this, []); | ||
_finish.set(this, void 0); | ||
_state.set(this, void 0); | ||
this.logger.setLabel(`Disposer(${label})`); | ||
__classPrivateFieldSet(this, _finish, finish); | ||
} | ||
@@ -52,3 +54,3 @@ get disposed() { | ||
__classPrivateFieldSet(this, _state, util_1.AsyncState.acquire()); | ||
for (const disposable of __classPrivateFieldGet(this, _disposable).splice(0)) { | ||
for (const disposable of [...__classPrivateFieldGet(this, _disposable).splice(0), __classPrivateFieldGet(this, _finish)]) { | ||
const date = new Date(); | ||
@@ -69,3 +71,3 @@ const target = (_b = (_a = disposable === null || disposable === void 0 ? void 0 : disposable.constructor) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : "Unknown"; | ||
} | ||
_disposable = new WeakMap(), _disposeHistory = new WeakMap(), _state = new WeakMap(); | ||
_disposable = new WeakMap(), _disposeHistory = new WeakMap(), _finish = new WeakMap(), _state = new WeakMap(); | ||
__decorate([ | ||
@@ -72,0 +74,0 @@ util_1.logger |
@@ -1,2 +0,2 @@ | ||
import { HeartbeatDisposer } from "./interfaces"; | ||
import { HeartbeatDisposer, IRunnable } from "./interfaces"; | ||
export declare class Heartbeat { | ||
@@ -13,2 +13,3 @@ #private; | ||
static create(target: unknown, disposer?: HeartbeatDisposer): Heartbeat; | ||
static watch(runnable: IRunnable): Promise<void>; | ||
static destroy(target: unknown): void; | ||
@@ -15,0 +16,0 @@ destroy(error?: Error): void; |
@@ -46,2 +46,6 @@ "use strict"; | ||
} | ||
static async watch(runnable) { | ||
const heartbeat = runnable.getHeartbeat(); | ||
return heartbeat.watch(); | ||
} | ||
static destroy(target) { | ||
@@ -48,0 +52,0 @@ const heartbeat = registry.get(target); |
@@ -17,6 +17,5 @@ import { Logger, Promisify } from "@bunt/util"; | ||
static run(...chain: ((runtime: Runtime) => Promisify<unknown>)[]): Promise<void>; | ||
accept(result: unknown): Promise<void>; | ||
dispose(): Promise<void>; | ||
accept(result: unknown): Promise<void>; | ||
private run; | ||
private release; | ||
} |
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
@@ -8,9 +14,2 @@ if (!privateMap.has(receiver)) { | ||
}; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to set private field on non-instance"); | ||
} | ||
privateMap.set(receiver, value); | ||
return value; | ||
}; | ||
var _disposed; | ||
@@ -29,10 +28,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
_disposed.set(this, false); | ||
this.logger = util_1.Logger.factory(this); | ||
this.created = new Date(); | ||
this.logger.info("register", { ENV, DEBUG }); | ||
this.accept(this.logger); | ||
// @TODO Send an event when a signal has been received. | ||
for (const signal of internal_1.Signals) { | ||
this.logger.debug("listen", signal); | ||
process.on(signal, async () => this.online && this.release()); | ||
process.on(signal, async () => this.online && this.dispose()); | ||
} | ||
@@ -62,5 +59,2 @@ } | ||
} | ||
async dispose() { | ||
return; | ||
} | ||
async accept(result) { | ||
@@ -78,2 +72,7 @@ const done = await result; | ||
} | ||
async dispose() { | ||
this.logger.info("dispose"); | ||
util_1.assert(this.online, "Runtime has been already released"); | ||
process.exit(0); | ||
} | ||
async run(...chain) { | ||
@@ -94,15 +93,11 @@ const finish = this.logger.perf("run"); | ||
if (this.online) { | ||
process.nextTick(() => this.release()); | ||
process.nextTick(() => Application_1.dispose(this)); | ||
} | ||
} | ||
async release() { | ||
this.logger.info("release"); | ||
util_1.assert(this.online, "Runtime has been already released"); | ||
__classPrivateFieldSet(this, _disposed, true); | ||
this.dispose(); | ||
process.exit(0); | ||
} | ||
} | ||
_disposed = new WeakMap(); | ||
__decorate([ | ||
util_1.logger | ||
], Runtime.prototype, "logger", void 0); | ||
exports.Runtime = Runtime; | ||
_disposed = new WeakMap(); | ||
//# sourceMappingURL=Runtime.js.map |
{ | ||
"name": "@bunt/unit", | ||
"version": "0.18.0", | ||
"version": "0.18.1", | ||
"keywords": [ | ||
@@ -32,3 +32,3 @@ "typescript" | ||
"license": "MIT", | ||
"gitHead": "21e4f7bc6fce2bdcb796b33dcccc9b3cdda6a8e3" | ||
"gitHead": "9b7005b18639871f88aff2f0d43b7b101e79fb26" | ||
} |
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
72175
949