MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / LogsChannel

Method LogsChannel

internal/nodeapi/api.go:112–143  ·  view source on GitHub ↗

LogsChannel 返回一个把 xray 历史 + 实时日志统一推出的只读通道。 ctx 取消时通道会被关闭。底层基于 coremanager.Manager 的 Subscribe/Unsubscribe。 返回的 chan 会先发送当前缓冲区的全部历史行,然后转入实时订阅模式。

(ctx context.Context)

Source from the content-addressed store, hash-verified

110//
111// 返回的 chan 会先发送当前缓冲区的全部历史行,然后转入实时订阅模式。
112func (a *API) LogsChannel(ctx context.Context) <-chan string {
113out := make(chan string, 64)
114mgr := a.activeManager()
115go func() {
116defer close(out)
117for _, line := range mgr.Logs() {
118select {
119case out <- line:
120case <-ctx.Done():
121return
122}
123}
124id, ch := mgr.Subscribe()
125defer mgr.Unsubscribe(id)
126for {
127select {
128case <-ctx.Done():
129return
130case line, ok := <-ch:
131if !ok {
132return
133}
134select {
135case out <- line:
136case <-ctx.Done():
137return
138}
139}
140}
141}()
142return out
143}
144
145// DoStart 启动核心,返回最新 Status。
146func (a *API) DoStart(config, core string) (coremanager.Status, error) {

Callers 1

handleLogsStreamMethod · 0.80

Calls 5

activeManagerMethod · 0.95
LogsMethod · 0.65
DoneMethod · 0.65
SubscribeMethod · 0.65
UnsubscribeMethod · 0.65

Tested by

no test coverage detected