feat: harden support, localize knowledge and add operator availability [skip ci]
Source-only publication of reviewed commit 64e96a7f423673dc29ad56485be9fc79bce8af1c.
Passed in isolation: focused frontend/backend tests, race checks, TypeScript typecheck, lint, Go compilation, Flowgram build, and deterministic SDK build/tests.
Not accepted as a production release: Next.js export/native assembly remains blocked by environment memory limits; browser interaction and MySQL staging acceptance remain unverified. No production server, database/schema, runtime configuration, deployment, release tag, or workflow execution was performed.
Expected source tree: 0a4a7528e9.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// Modified by the independent AgentDesk fork for support reliability and availability.
|
||||
package eventbus
|
||||
|
||||
import (
|
||||
@@ -28,6 +29,7 @@ type Bus[T any] struct {
|
||||
|
||||
// 用于限制 PublishAsync 的 goroutine 并发数;nil 表示不限制
|
||||
asyncSem chan struct{}
|
||||
asyncWG sync.WaitGroup
|
||||
}
|
||||
|
||||
func New[T any](opts ...Option[T]) *Bus[T] {
|
||||
@@ -130,10 +132,21 @@ func (b *Bus[T]) Publish(ctx context.Context, event T) error {
|
||||
func (b *Bus[T]) PublishAsync(ctx context.Context, event T) {
|
||||
handlers := b.snapshotHandlers()
|
||||
for _, h := range handlers {
|
||||
go b.callHandlerAsync(ctx, h, event)
|
||||
b.asyncWG.Add(1)
|
||||
go func() {
|
||||
defer b.asyncWG.Done()
|
||||
b.callHandlerAsync(ctx, h, event)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
// Wait blocks until already-published asynchronous handlers and their error
|
||||
// callbacks finish. Stop external publishers before calling Wait; a handler
|
||||
// may still publish nested work while its own invocation is pending.
|
||||
func (b *Bus[T]) Wait() {
|
||||
b.asyncWG.Wait()
|
||||
}
|
||||
|
||||
func (b *Bus[T]) HandlerCount() int {
|
||||
b.mu.RLock()
|
||||
defer b.mu.RUnlock()
|
||||
|
||||
Reference in New Issue
Block a user