refactor: 清掉指向不存在的 Dispatch 的文档,删掉为它留的死导出

Dispatch 在仓库里出现 7 次,全是注释和错误文案,没有任何实现。三处错误文案
写着「需要回调语义请用 Dispatch」——使用者按这句去查会找不到东西,真正该指的
是 WithCall。caller.go 那句还指向不存在的子包 jscriptx/dispatch。

连带删掉四个为它留的导出(全仓库零调用):

  Target                   统一 Script/Instance 的接口。有未导出方法 owner(),
                           外部实现不了;也没有任何函数以它为参数或返回值
  ErrUnsupportedSignature  哨兵错误,库自己从不产生它
  KindSignature            错误分类,全仓库唯一一次出现就是它自己的声明。
                           留着会让写 switch 的人为一个永不出现的分支写代码
  OverlayLoader.Loaders    零调用的 getter,连测试都没有

另外删掉 Instance.IdleFor 和 lastUsed 字段:它是给「空闲回收」用的,而
doc.go 明确写着本库不代管实例生命周期、没有空闲回收——字段注释和包文档直接
对立。代价是每次 Call 白付两次 time.Now() + atomic store。业务侧真要自己回收,
记一个时间戳是一行的事。

caller 的示例原来拿 ErrUnsupportedSignature 当哨兵,改成自己声明一个——
回调签名的约定本来就是调用方定的,哨兵该归调用方。

验证:framework-v2 和 lx-bid 都仍能编译。
This commit is contained in:
2026-09-10 15:15:10 +08:00
parent ad722b12f9
commit 9b3509ae29
7 changed files with 28 additions and 59 deletions
+2 -21
View File
@@ -22,7 +22,8 @@ import (
// return nil
// })
//
// 框架自己的回调约定(比如 orm 那套种签名)就是这么实现的,见 jscriptx/dispatch。
// 框架自己的回调约定(比如 orm 那套「一元/二元」两种签名)就是这么实现的
// 先用 Arity 看脚本写了几个形参,再决定怎么调。
//
// Caller 只在 do 回调执行期间有效,别存下来跨调用用。
type Caller interface {
@@ -118,23 +119,3 @@ func (r *result) Into(out any) error {
}
return nil
}
// Target 是能发起脚本调用的对象:*Script(从 VM 池借用,脚本无跨调用状态)
// 或 *Instance(独占一个 VM,脚本里的状态跨调用保持)。
//
// 这个接口不对外开放实现,只是让 dispatch 这类函数能同时接受两者。
type Target interface {
// Name 返回脚本名。
Name() string
// Has 判断脚本里有没有这个函数。
Has(fn string) bool
// Call 调用脚本函数,返回值导出成 Go 值。
Call(ctx context.Context, fn string, args ...any) (any, error)
// CallInto 调用脚本函数,并把返回值转换进 out 指向的变量。
CallInto(ctx context.Context, fn string, out any, args ...any) error
// WithCall 借一个 VM,在借出期间把控制权交给 do,用来实现自定义的调用约定。
WithCall(ctx context.Context, fn string, do func(Caller) error) error
// 未导出方法,接口不对外开放实现。
owner() *Script
}