Skip to content

Commit

Permalink
GitBook: [master] one page modified
Browse files Browse the repository at this point in the history
  • Loading branch information
yemreak authored and gitbook-bot committed Jan 23, 2020
1 parent e483539 commit 74d59a9
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions coroutine/giris.md
Expand Up @@ -62,6 +62,9 @@ fun main() = runBlocking<Unit> {

## 🏗️ İş Oluşturma

* 🏃‍♂️ Thread nesnelerinden farklı olarak Job hemen başlatılır
* ✋ Durdurmak için `cancel` metodu kullanılır

```kotlin
val job = GlobalScope.launch { // Coroutine oluşturma (thread oluşturma gibi)
delay(1000L)
Expand All @@ -71,6 +74,25 @@ println("Hello,")
job.join() // Coroutine bitene kadar bekleme (thread.join() gibi)
```

```kotlin
val startTime = System.currentTimeMillis()
val job = launch(Dispatchers.Default) {
var nextPrintTime = startTime
var i = 0
while (isActive) { // cancellable computation loop
// print a message twice a second
if (System.currentTimeMillis() >= nextPrintTime) {
println("job: I'm sleeping ${i++} ...")
nextPrintTime += 500L
}
}
}
delay(1300L) // delay a bit
println("main: I'm tired of waiting!")
job.cancelAndJoin() // cancels the job and waits for its completion
println("main: Now I can quit.")
```

## 💠 Suspend Metotlar

* 🚫 Coroutine içeren metotlar `suspent` anahtarı ile belirtilir
Expand Down

0 comments on commit 74d59a9

Please sign in to comment.