Skip to content

Instantly share code, notes, and snippets.

@brailateo
Last active October 26, 2017 06:12
Show Gist options
  • Save brailateo/6018021 to your computer and use it in GitHub Desktop.
Save brailateo/6018021 to your computer and use it in GitHub Desktop.
Generator automat de numere seriale în Go
func jobIdGenerator(init int) chan int {
ids := make(chan int)
go func() {
id := init //intializare cu ultimul nr din baza de date
for {
id++
ids <- id
}
}()
return ids
}
...
var jobExecSerialNumberGenerator chan int
jobExecSerialNumberGenerator = jobIdGenerator(startValue)
...
idJob := <- jobExecSerialNumberGenerator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment