procxy / isProcxy
Function: isProcxy()
ts
function isProcxy<T>(obj): obj is Procxy<T, any, any>;Defined in: src/types/isomorphism.ts:298
Runtime type guard that returns true when obj is a live Procxy proxy.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
obj | MaybeProxy<T> | A value that is either the original type T or a Procxy<T> |
Returns
obj is Procxy<T, any, any>
true when obj has the Procxy lifecycle interface
Remarks
Detection is duck-typed: the function checks for the presence of $terminate (function) and $process (object) on the value. This is reliable for procxy-created proxies but could yield a false positive for hand-crafted objects that happen to have those properties.
Example
typescript
import { procxy, isProcxy } from 'procxy';
import { Calculator } from './calculator.js';
function processWorker(worker: Calculator | Procxy<Calculator>) {
if (isProcxy(worker)) {
console.log('Remote proxy, PID:', worker.$process.pid);
} else {
console.log('Local instance');
}
}See
isAdvancedMode — check whether a proxy uses advanced serialization