| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
- 코틀린멀티플랫폼
- 함수형프로그래밍
- Coroutines
- PrototypePattern
- builderPattern
- designPattern
- 안드로이드 디자인시스템
- material3
- 팩토리 메소드
- kmp
- Observer Pattern
- 옵저버 패턴
- 추상팩토리패턴
- factory method
- android designsystem
- 디자인패턴
- ㅋㅁ
- Functional Programming
- 코루틴
- Abstract Factory
- 디자인패턴 #
- compose
- define
- Kotlin
- 코틀린
- 프로토타입 패턴
- kotlin multiplatform
- 추상 팩토리
- 빌터패턴
- Design Pattern
- Today
- Total
목록Coroutine (34)
오늘도 더 나은 코드를 작성하였습니까?
잡히지 않은 예외가 발생하면, 프로그램이 종료하듯 코루틴도 잡히지 않은 예외가 발생했을때 종료합니다.코루틴 빌더는 부모도 종료시키며, 취소된 부모는 자식들 모두를 취소시킨다.import kotlinx.coroutines.delayimport kotlinx.coroutines.launchimport kotlinx.coroutines.runBlockingfun main(): Unit = runBlocking { launch { launch { delay(1000) throw Error("some error") } launch { delay(2000) println("Will not be ..
취소는 매우 중요하여 중단함수를 사용하는 몇몇 클래스와 라이브러리는 취소를 반드시 지원한다.기본적인 취소job 인터페이스는 취소를 가능하게 하는 cancel 메서드를 가지고 있다. cancel- 첫 번째 중단점에서 job을 종료한다.- 자식 코루틴을 가지고 있다면 종료한다. 하지만 부모에게는 영향을 주이 않는다.- 취소되면, 새로운 코루틴의 부모가 될수 없다.import kotlinx.coroutines.*suspend fun main(): Unit = coroutineScope { val job = launch { repeat(1_000) { i -> delay(200) println("printing $i") } } de..
구조화된 동시성 (부모-자식)- 자식은 부모로부터 CoroutineContext를 상속받는다.- 부모는 모든 자식이 작업을 마무리 지을때까지 기다립니다.- 부모 Coroutine이 취소되면 자식 Coroutine도 취소된다. - 자식 Coroutine에서 에러가 발생하면 부모 자식 Coroutine도 에러로 소멸한다. Job- Coroutine을 취소하고, 상태를 파악하는 등 다양하게 활용된다.Job이란 무엇인가?수명을 가지고 있으며 취소 가능하다Active- job이 실행되고, 코루틴은 잡을 수행한다. job이 코루틴 빌더에 의해 생성되었을 때, 코루틴의 본체가 실행되는 상태 - 자식 코루틴을 시작 시킬수 있다. New- 지연 시작되는 코루틴의 시작 상태.- 실행하면, Active 상태가 됨 Compl..
public fun CoroutineScope.launch( context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> Unit): Job { ... } 코루틴 빌더의 첫번째 인자는 CoroutineContext 이다.마지막 인자인 block의 리시버 타입은 CoroutineScope이다.public interface CoroutineScope { public val coroutineContext: CoroutineContext} CoroutineScope는 CoroutineContext의 랩퍼처럼 보인..