f3abc5fdc6
Deploy Slides / build-and-deploy (push) Successful in 1m39s
- eino-deep-dive.md: split slide 2 into code-only + explanation+SVG slides - async-deep-dive.md: split slide 2 into code-only + progress+SVG slides - harness.md: split slide 2 (4 Items + SVG) into two slides (2 Items each) - request-journey.md: split into middleware/handler + pipeline/finalization slides The frankfurt theme header (~40px) overlaps ~7px into the content zone, leaving ~467px effective height. Dense slides with code+Items+images exceeded this budget and were hidden behind the bars.
2.0 KiB
2.0 KiB
异步任务 — 队列与调度
FIFO 串行执行,信号驱动调度
type TaskQueue struct {
mu sync.Mutex
jobs []*TaskJob
ready chan struct{} // 新任务到达信号
stop chan struct{} // 优雅关闭信号
}
func (q *TaskQueue) Enqueue(job *TaskJob) {
q.mu.Lock()
q.jobs = append(q.jobs, job)
q.mu.Unlock()
q.ready <- struct{}{} // 唤醒 run() 协程
}
提交任务入队并发送信号。`run()` 协程阻塞等待信号,收到后调用 `processNext()` 取队首任务执行。FIFO 保证任务按提交顺序串行处理。
`TaskJob` 封装了 `context.Context` 和执行函数。闭包捕获任务参数,context 控制超时和取消,确保每个任务独立且可中断。
进度推送与 WebSocket
Context 注入 + 多通道推送
func WithProgressReporter(ctx context.Context, r ProgressReporter) context.Context {
return context.WithValue(ctx, progressCtxKey, r)
}
// 管线节点中使用
reporter := GetProgressReporter(ctx)
reporter.Report(Progress{Stage: "prompt", Percent: 25})