@opvious/stl-utils
Advanced tools
@@ -34,8 +34,12 @@ import http from 'http'; | ||
| declare const isBindableMarker: "@opvious/stl-utils/bindable:isBindable+v1"; | ||
| export interface BindableOptions { | ||
| readonly emitProcessEvents?: boolean; | ||
| } | ||
| export declare abstract class Bindable extends TypedEmitter<BindableListeners> { | ||
| static [Symbol.hasInstance](val: unknown): val is Bindable; | ||
| private readonly [isBindableMarker]; | ||
| private readonly sendProcessEvent; | ||
| private status; | ||
| private activeHost; | ||
| protected constructor(); | ||
| protected constructor(opts?: BindableOptions); | ||
| /** Returns the host to bind to. Called internally by `start`. */ | ||
@@ -42,0 +46,0 @@ protected abstract bind(): Promise<Host & HasPort>; |
+10
-9
@@ -1,2 +0,2 @@ | ||
| import { assert, errors } from '@opvious/stl-errors'; | ||
| import { assert, check, errors } from '@opvious/stl-errors'; | ||
| import net from 'net'; | ||
@@ -61,6 +61,9 @@ import { TypedEmitter, waitForEvent, withEmitter } from './events.js'; | ||
| } | ||
| constructor() { | ||
| constructor(opts) { | ||
| super(); | ||
| this.status = 'unbound'; | ||
| Object.defineProperty(this, isBindableMarker, { value: true }); | ||
| this.sendProcessEvent = opts?.emitProcessEvents | ||
| ? check.isPresent(process.send) | ||
| : undefined; | ||
| } | ||
@@ -99,9 +102,7 @@ updateStatus(next, prev) { | ||
| this.emit('bound', host); | ||
| if (process.send) { | ||
| process.send({ | ||
| event: 'bindableBound', | ||
| port: host.port, | ||
| address: host.name, | ||
| }); | ||
| } | ||
| this.sendProcessEvent?.({ | ||
| event: 'bindableBound', | ||
| port: host.port, | ||
| address: host.name, | ||
| }); | ||
| }); | ||
@@ -108,0 +109,0 @@ return this; |
+3
-3
| { | ||
| "name": "@opvious/stl-utils", | ||
| "version": "0.26.0", | ||
| "version": "0.26.1", | ||
| "repository": "github:opvious/stl.ts", | ||
@@ -33,6 +33,6 @@ "description": "Standard utilities", | ||
| "fast-deep-equal": "^3.1.3", | ||
| "inlinable-runtime": "^0.3.3", | ||
| "inlinable-runtime": "^0.3.4", | ||
| "picomatch": "^4.0.2", | ||
| "untruncate-json": "^0.0.1", | ||
| "@opvious/stl-errors": "0.26.0" | ||
| "@opvious/stl-errors": "0.26.1" | ||
| }, | ||
@@ -39,0 +39,0 @@ "devDependencies": { |
106302
0.21%2593
0.19%+ Added
- Removed
Updated
Updated