小编use*_*460的帖子

Go lang保持功能活着

我有一个go函数,它会在Channel收到一些逻辑之后做一些逻辑.

我的问题是我希望函数在完成逻辑后保持活跃.我的想法是

我将在函数中添加无限循环.但是,我想知道这是不是

一个好的技术.我的守则如下:

func process(channel chan string, sid string) {
    inputSid := <-channel

    // check if sid exist in process pool
    if strings.EqualFold(sid, inputSid) {
        fmt.Println("Got message", sid)

         //the code that I added to make this function alive
         for {} 

    } else {
        channel <- sid

        //the code that I added to make this function alive
         for {} 

    }
}
Run Code Online (Sandbox Code Playgroud)

go while-loop

0
推荐指数
2
解决办法
349
查看次数

标签 统计

go ×1

while-loop ×1