dgreceanu of The Code Killers
1/29/2014 - 8:44 PM

Generator numar unic crescator

Generator numar unic crescator

func idGenerator() chan int {
    ids := make(chan int)
    go func() {
        id := 0 //intializare cu ultimul nr din baza de date
        for {
            id++
            ch <- id
        }
    }()
    return ids
}

ids := idGenerator()
id1 := <-ids
id2 := <-ids