Replies: 1 comment 3 replies
-
Hi, How about passing a struct to your channel? It can then contain a context. Something like this (untested): type msg struct {
ctx context.Context
val int
}
var (
cha = make(chan msg, 10)
chb = make(chan msg, 10)
)
func (a *moduleA) run(cha chan int) {
for {
select {
case data := <-cha:
ctx, span := tracer.Start(data.ctx, "moduleA")
// doSomeTask
chb <- msg{ctx, 2 * num}
// doSomeTask
span.End()
}
}
}
func (a *moduleB) run(chb chan int) {
for {
select {
case data := <-chb:
ctx, span := tracer.Start(data.ctx, "moduleB")
// doSomeTask
time.Sleep(time.Second * 10)
span.End()
}
}
}
func main() {
exit := make(chan struct{}, 1)
modA := &moduleA{}
modB := &moduleB{}
go modA.run(cha)
go modB.run(chb)
cha <- msg{context.Background(), 1} // push msg to queue cha
<-exit
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Scene Call In Gorutinues
“modB.run” groutinue is driven by channel chb and In "modA.run" goroutinue we put a message to chb.Is there any way to handle this situation when we tracing go program:
Beta Was this translation helpful? Give feedback.
All reactions