# Closing Channels

Go dilində, channel-ların bağlanması, məlumatların göndərilməsi və alınması prosesində sinxronizasiyanı təmin edir. `close` funksiyası vasitəsilə channel bağlanır. Bağlanmış bir channel-a mesaj göndərmək mümkün deyil və həmin channel-dan daha çox mesaj alınmaz.

```go
package main

import "fmt"

func main() {
	jobs := make(chan int, 5)
	done := make(chan bool)

	go func() {
		for {
			j, more := <-jobs
			if more {
				fmt.Println("received job", j)
			} else {
				fmt.Println("received all jobs")
				done <- true
				return
			}
		}
	}()

	for j := 1; j <= 3; j++ {
		jobs <- j
		fmt.Println("sent job", j)
	}

	close(jobs)
	fmt.Println("sent all jobs")

	<-done
}
```

Bu nümunədə:

* `jobs` adlı bir channel yaradılır və işlər bu kanala göndərilir.
* `done` adlı bir channel yaradılır və işlərin tamamlandığını bildirmək üçün istifadə olunur.
* Bir `goroutine` yaradılır və bu `goroutine`, `jobs` channel-ından mesajları alır. Alınan mesajların sayı azaldıqca hər dəfə "received job" yazısı çap edilir.
* `for` döngüsü ilə `jobs` channel-ına 3 iş göndərilir və hər göndərmə zamanı "sent job" mesajı göstərilir.
* `jobs` channel-ı bağlandıqdan sonra `goroutine`, channel-dan bütün mesajları alır və son olaraq "received all jobs" mesajı göstərilir.

#### Output:

```go
sent job 1
sent job 2
sent job 3
sent all jobs
received job 1
received job 2
received job 3
received all jobs
```

Bu nümunə, Go dilində bir channel-a mesaj göndərdikdən sonra onu necə bağlayacağınızı və bağlanmış channel-dan daha çox mesaj alınmadığını göstərir. Bağlı bir channel-dan oxumağa davam edə bilərsiniz, lakin artıq yeni mesajlar göndərilə bilməz.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.golang.az/closing-channels.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
