@bunt/unit
Advanced tools
Comparing version 0.19.0 to 0.19.1
@@ -6,2 +6,13 @@ # Change Log | ||
## [0.19.1](https://github.com/izatop/bunt/compare/v0.19.0...v0.19.1) (2021-05-26) | ||
### Bug Fixes | ||
* runtime ([b7764fb](https://github.com/izatop/bunt/commit/b7764fbab34192903f59fa0b4d935a261822fe10)) | ||
# [0.19.0](https://github.com/izatop/bunt/compare/v0.18.3...v0.19.0) (2021-05-26) | ||
@@ -8,0 +19,0 @@ |
/// <reference types="node" /> | ||
import { Promisify } from "@bunt/util"; | ||
import { IDisposable, IRunnable } from "./interfaces"; | ||
import { Runtime } from "./Runtime"; | ||
export declare const Signals: NodeJS.Signals[]; | ||
export declare function isDisposable(target: unknown): target is IDisposable; | ||
export declare function isRunnable(target: unknown): target is IRunnable; | ||
export declare function main(...chain: ((runtime: Runtime) => Promisify<unknown>)[]): void; | ||
export declare function main(...chain: (() => Promisify<unknown>)[]): void; |
@@ -14,6 +14,7 @@ import { Logger, Promisify } from "@bunt/util"; | ||
static isTest(): boolean; | ||
static run(...chain: ((runtime: Runtime) => Promisify<unknown>)[]): Promise<void>; | ||
handle(result: unknown): Promise<void>; | ||
static run(...chain: (() => Promisify<unknown>)[]): Promise<void>; | ||
static createQueue(chain: (() => Promisify<unknown>)[]): Promise<unknown>[]; | ||
dispose(): Promise<void>; | ||
private run; | ||
private watch; | ||
private handle; | ||
} |
@@ -43,28 +43,25 @@ "use strict"; | ||
static run(...chain) { | ||
const runtime = ref.create(() => new Runtime()); | ||
return runtime.run(...chain); | ||
const queue = this.createQueue(chain); | ||
return ref.create(() => new Runtime()) | ||
.watch(queue); | ||
} | ||
async handle(result) { | ||
const object = await result; | ||
if (util_1.isUndefined(object) || util_1.isNull(object)) { | ||
return; | ||
static createQueue(chain) { | ||
const queue = []; | ||
for (const callback of chain) { | ||
queue.push(new Promise((resolve) => resolve(callback()))); | ||
} | ||
if (internal_1.isRunnable(object)) { | ||
this.queue.push(object.getHeartbeat()); | ||
} | ||
if (internal_1.isDisposable(object)) { | ||
Dispose_1.Disposable.attach(this, object); | ||
} | ||
return queue; | ||
} | ||
async dispose() { | ||
this.logger.info("dispose"); | ||
await Dispose_1.Disposable.disposeAll(); | ||
process.exit(0); | ||
} | ||
async run(...chain) { | ||
async watch(chain) { | ||
const finish = this.logger.perf("run"); | ||
try { | ||
for (const callback of chain) { | ||
await this.handle(callback(this)); | ||
for (const pending of chain) { | ||
await this.handle(pending); | ||
} | ||
await Promise.allSettled(this.queue.map((hb) => hb.watch())); | ||
await Promise.allSettled(this.queue.map((heartbeat) => heartbeat.watch())); | ||
} | ||
@@ -77,5 +74,21 @@ catch (error) { | ||
} | ||
await Dispose_1.dispose(this); | ||
await Dispose_1.Disposable.disposeAll(); | ||
Dispose_1.dispose(this); | ||
} | ||
async handle(result) { | ||
try { | ||
const object = await result; | ||
if (util_1.isUndefined(object) || util_1.isNull(object)) { | ||
return; | ||
} | ||
if (internal_1.isRunnable(object)) { | ||
this.queue.push(object.getHeartbeat()); | ||
} | ||
if (internal_1.isDisposable(object)) { | ||
Dispose_1.Disposable.attach(this, object); | ||
} | ||
} | ||
catch (error) { | ||
this.logger.error("reject", error); | ||
} | ||
} | ||
} | ||
@@ -82,0 +95,0 @@ __decorate([ |
{ | ||
"name": "@bunt/unit", | ||
"version": "0.19.0", | ||
"version": "0.19.1", | ||
"keywords": [ | ||
@@ -32,3 +32,3 @@ "typescript" | ||
"license": "MIT", | ||
"gitHead": "8e62b6bb684e9b7cc47b50f0be41c04020e1f9e7" | ||
"gitHead": "a692c96ce4a9e62d97635d280de51a611b8d5bb6" | ||
} |
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
76248
986