# coroutine.wrap

- **Ortam:** İstemci, Sunucu, Menü
- **İngilizce aslı:** https://wiki.facepunch.com/gmod/coroutine.wrap
- **Çeviri tarihi:** 2025-09-08

```lua
function coroutine.wrap( function coroutine )
```

## Açıklama

Çağrılması, coroutine ve tüm ek parametrelerle birlikte [coroutine.resume](https://gmod.tr/wiki/coroutine.resume)'ı çağırmakla eşdeğer olan bir fonksiyon döndürür.

Döndürülen fonksiyon tarafından geri verilen değerler yalnızca içteki [coroutine.yield](https://gmod.tr/wiki/coroutine.yield) çağrısına iletilen değerleri içerir ve [coroutine.resume](https://gmod.tr/wiki/coroutine.resume)'ın sağladığı *hata yok* durumunu içermez. Başarısızlık durumunda bunun yerine bir hata fırlatılır.

## Argümanlar

1. [function](https://gmod.tr/wiki/function) **coroutine**: Devam ettirilecek coroutine.

## Döndürülen Değerler

1. [function](https://gmod.tr/wiki/function)

### Örnek

Kodun yürütülmesine devam etmek için sunucu yanıtını beklerken standart bir HTTP isteği gerçekleştirir. Kodun okunabilirliğini artırmak ve geri arama (callback) fonksiyonlarını kullanmaktan kaçınmak için faydalıdır.

```lua
local function HTTPRequest( url, headers )
    local running = coroutine.running()

    local function onSuccess( body, length, header, code )
        coroutine.resume( running, true, body )
    end

    local function onFailure( err )
        coroutine.resume( running, false, err )
    end

    http.Fetch( url, onSuccess, onFailure, headers )

    return coroutine.yield()
end

coroutine.wrap( function()
    local state, response = HTTPRequest( "https://www.google.com/" )

    if state then
        -- Başarılı!
        print( "HTTP gövdesi:" .. response )
    else
        -- Hata(?)
        print( "HTTP isteği hatası: " .. response )
    end

	-- İstek tamamlandıktan sonra gerçekleştirilecek önemli kod..
end )()
```

**Çıktı:** İstek başarılıysa HTTP sayfasının gövdesi, aksi takdirde başarısızlık durumunda hata kodu.

- [GMod Wiki ana sayfası](https://gmod.tr/wiki)

---

[Tüm sunucular](https://gmod.tr/) · [GmodTR Launcher](https://gmod.tr/launcher) · [Rehber](https://gmod.tr/rehber) · [GMod Wiki](https://gmod.tr/wiki) · [GmodTR nedir?](https://gmod.tr/hakkinda) · [Sunucu ekle](https://gmod.tr/sunucu-ekle) · [Discord](https://discord.gg/gmodtr)

Kaynak: https://gmod.tr/wiki/coroutine.wrap
