Skip to content
English

BreakWhileConfig ​

CORE · interface · 类型合同

Global rejection observer installed once per process.

导入 ​

ts
import type { BreakWhileConfig } from '@jangts/agent-core/support';
js
/** @typedef {import('@jangts/agent-core/support').BreakWhileConfig} BreakWhileConfig */

其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/support。

定义 ​

ts
interface BreakWhileConfig

字段结构 ​

字段类型必需说明
onBreak((event: BreakEvent) => void | Promise<void>) | undefined可省略只读。Called before the reason is thrown; its errors are swallowed and promises are not awaited.

使用示例 ​

一个明确的拒绝 ​

入门 · 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);

有依赖关系的检查按序求值 ​

配置 · 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);

相关策略源码 ​

相关定义 ​

接口参考、使用示例与开发指南。