BreakWhileConfig
CORE · interface · Type contract
Global rejection observer installed once per process.
Import
ts
import type { BreakWhileConfig } from '@jangts/agent-core/support';js
/** @typedef {import('@jangts/agent-core/support').BreakWhileConfig} BreakWhileConfig */Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs, @jangts/agent-core/support.
Definition
ts
interface BreakWhileConfigField structure
| Field | Type | Required | Description |
|---|---|---|---|
onBreak | ((event: BreakEvent) => void | Promise<void>) | undefined | Optional | Read-only. Called before the reason is thrown; its errors are swallowed and promises are not awaited. |
Examples
- Rejection checks, first match, and sequential processing: Use real lists to express multiple checks and enumerated dispatch; a single ordinary condition can still use if.
One explicit rejection
Beginner · Node.js
ts
import { Support } from '@jangts/agent-core';
const input = '你好';
Support.breakWhile(!input.trim(), '问题不能为空');
console.log(input);js
import { Support } from '@jangts/agent-core';
const input = '你好';
Support.breakWhile(!input.trim(), '问题不能为空');
console.log(input);Checks with dependencies evaluated in order
Configuration · Node.js
ts
import { Support } from '@jangts/agent-core';
const input: unknown = { name: 'Ivan' };
Support.breakWhile([
{ occur: !input || typeof input !== 'object', error: '需要对象' },
{ occur: () => !('name' in (input as object)), error: '缺少 name' },
]);
console.log(input);js
import { Support } from '@jangts/agent-core';
const input = { name: 'Ivan' };
Support.breakWhile([
{ occur: !input || typeof input !== 'object', error: '需要对象' },
{ occur: () => !('name' in input), error: '缺少 name' },
]);
console.log(input);