# Goroutine

## Coroutine in Go&#x20;

```go
func integers() chan int {
    yield := make(chan int)
    count := 0
    go func() {
        for {
            yield <- count
            count++
        }
    }()
    return yield
}

func generateInteger(resume chan int) int {
  	return <-resume
}

func main() {
	resume := integers()  // prime the generator 
	fmt.Println(generateInteger(resume))  // 0
	fmt.Println(generateInteger(resume))  // 1
	fmt.Println(generateInteger(resume))  // 2 
}
```

## References

* Google I/O 2012 - Go Concurrency Patterns&#x20;
* Go Language Patterns - [Coroutines](http://www.golangpatterns.info/concurrency/coroutines)&#x20;
