go – Function calling itself as a goroutine, is this dangerous?-ThrowExceptions

Exception or error:

I’m not sure is this will generate a leak. I’m assuming that, since I’m returning the function GetFile after launching the go routine its probably ok. But I’m not sure if it could be a problem, eg. no file is found in a long time.

func (p *MyStruct) Launch() {
   go p.Generate()
}

func (p *MyStruct) Generate() {
    file := p.GetFile()
    if file == "" {
         return
    }

    // Do stuff with the file
}

func (p *MyStruct) GetFile() string {
    // Get file
    *p.SyncChan <- id
    fileToProcess, err := tools.ReserveFile(p.Name, id, p.BufferIndex)
    <- *p.SyncChan

    if fileToProcess == "" {
        time.Sleep(time.Minute * 6)
        go p.Generate()
        return ""
    }
    return fileToProcess
}
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *