김누누
close
프로필 배경
프로필 로고

김누누

  • 분류 전체보기 (252)
    • Deep Dive (49)
      • Kotlin Coroutine (18)
      • Kotlin Flow (6)
      • Test Code (12)
      • Android Jetpack Compose (9)
      • Flutter (4)
    • [Android] Architecture (14)
      • Architecture Pattern (5)
      • [Android] Multi Module (3)
      • [Android] DI (4)
    • [Kotlin] Tech,Study (18)
    • [Android] Tech,Study (65)
      • [Android] Trouble Shoot (20)
      • [Android] Custom (9)
    • Algorithm (13)
    • Computer Science (29)
      • 독서 (8)
      • 프로그래밍 (14)
      • 운영체제 (4)
      • 자료구조 (1)
      • 네트워크 (1)
    • GitHub (1)
    • Python,Django,DRF (13)
    • IOS,Swift (10)
    • 회고 (7)
  • 깃허브
  • 글쓰기
  • 설정
플로우 생명주기 함수

플로우 생명주기 함수

플로우 생명주기 함수플로우는 요청이 한쪽 방향으로 흐르고, 요청에 의해 생성된 값이 다른 방향으로 흐르는 파이프 형태입니다.플로우가 완료되거나 예외가 발생하면 값이나 예외 같은 특정 이벤트를 감지할 수 있습니다.이 때 onEach, onStart, onCompletion, onEmpty와 같은 catch 메서드를 사용할 수 있습니다.onEachonEach는 중단 함수로, 순서대로 값을 하나씩 받아 처리할 수 있습니다.suspend fun main() { flowOf(1,2,3,4) .onEach { delay(1000) } .collect{ println(it) }}onEmpty예기치 않은 이벤트가 발생하면 플..

  • format_list_bulleted Deep Dive/Kotlin Coroutine
  • · 2025. 2. 10.
  • textsms
플로우 구현하기

플로우 구현하기

플로우 만들기플로우는 어디선가 시작되어야 하며, 필요한 경우에 따라 다양하게 시작할 수 있습니다.원시값을 가지는 플로우플로우를 가지는 가장 간단한 방법은 flowOf를 활용하는 것입니다.suspend fun main() { flowOf(1, 2, 3, 4, 5) .collect { print(it) }}컨버터asFlow 함수를 사용하여 Iterable, Iterator, Sequence를 Flow로 바꿀 수 있습니다.// asFlow 함수를 이용해 즉시 사용 가능한 원소들의 플로우를 만들 수 있습니다.suspend fun main(){ sequenceOf(1,2,3,4,5) // sequenceOf .toSet() //setOf .toList() // li..

  • format_list_bulleted Deep Dive/Kotlin Coroutine
  • · 2025. 2. 10.
  • textsms
Coroutine 에러 핸들링 with CoroutineExceptionHandler

Coroutine 에러 핸들링 with CoroutineExceptionHandler

💡Coroutine 사용 중에 발생한 에러를 CoroutineExceptionHandler를 활용하여 핸들링 하는 방법에 대하여 기록하였습니다. 개요코루틴 내부에서 예외가 발생했을 때 try - catch 블럭이나 runcatching을 활용하여 예외를 감싸 처리하는 방법이 있습니다. 다른 방법으로는 CoroutineExceptionHandler를 활용하는 방안이 있는데, 코루틴에서 발생한 예외를 처리하고 앱의 비정상 종료를 방지할 수 있습니다.CoroutineExceptionHandlerCoroutineExceptionHandler는 Kotlin의 코루틴에서 발생한 예외를 처리하기 위한 방법으로 주로 비동기 작업에 활용됩니다.전역적으로 예외 처리를 할 수 있는 방법을 제공하며, 취소되지 않은 코루틴에..

  • format_list_bulleted Deep Dive/Kotlin Coroutine
  • · 2024. 9. 12.
  • textsms
Coroutine의 IO vs Default Dispatcher

Coroutine의 IO vs Default Dispatcher

💡CoroutineDispatcher에서 IO와 Default의 차이에 대해서 학습하였습니다. CoroutineDispatcher코루틴 디스패처는 코루틴을 스레드로 보내는 역할을 합니다.모든 작업은 스레드 위에서 실행되어야 하고, 코루틴 또안 작업이므로 스레드 위에서만 실행할 수 있습니다.Coroutine은 스레드풀을 만들고 Dispatcher는 Coroutine을 적절한 Thread에 보내 작업을 수행할 수 있도록 배분합니다.CoroutineDispatcher CoroutineDispatcherCoroutineDispatcher Base class to be extended by all coroutine dispatcher implementations. If kotlinx-coroutines is u..

  • format_list_bulleted Deep Dive/Kotlin Coroutine
  • · 2024. 9. 8.
  • textsms
[Coroutine] 코틀린 코루틴 테스트

[Coroutine] 코틀린 코루틴 테스트

💡 코틀린 코루틴에서 테스트하는 방법에 대하여 학습하였습니다. 코틀린 코투린 테스트대부분의 경우 중단 함수를 테스트하는 것은 일반적인 함수를 테스트하는 것과 다르지 않습니다.class FetchUserUseCase( private val repo: UserDataRepository) { suspend fun fetchUserData(): User = coroutineScope { val name = async { repo.getName() } val friends = ascycn { repo.getFriends() } val profile async { repo.getProfile() } User( name = name.a..

  • format_list_bulleted Deep Dive/Kotlin Coroutine
  • · 2024. 8. 24.
  • textsms
[Coroutine] 공유 상태로 인한 문제

[Coroutine] 공유 상태로 인한 문제

💡 코루틴에서 발생할 수 있는 공유 상태로 인한 문제를 확인하고, 이를 동기화 블로킹을 통해 어떻게 해결할 수 있는지 학습하였습니다. 공유 상태로 인한 문제class UserDowloader( private val api : NetworkService) { private val users = mutableListOf() fun downloaded(): List = users.toList() suspend fun fetchUser(id: Int) { val newUser = api.fetchUser(id) users.add(newUser) }}위 코드는 동시 사용에 대한 대비가 되어 있지 않습니다.fetchUser 호출은 users를 변경하는데, 이 경..

  • format_list_bulleted Deep Dive/Kotlin Coroutine
  • · 2024. 8. 16.
  • textsms
  • navigate_before
  • 1
  • 2
  • 3
  • navigate_next
전체 카테고리
  • 분류 전체보기 (252)
    • Deep Dive (49)
      • Kotlin Coroutine (18)
      • Kotlin Flow (6)
      • Test Code (12)
      • Android Jetpack Compose (9)
      • Flutter (4)
    • [Android] Architecture (14)
      • Architecture Pattern (5)
      • [Android] Multi Module (3)
      • [Android] DI (4)
    • [Kotlin] Tech,Study (18)
    • [Android] Tech,Study (65)
      • [Android] Trouble Shoot (20)
      • [Android] Custom (9)
    • Algorithm (13)
    • Computer Science (29)
      • 독서 (8)
      • 프로그래밍 (14)
      • 운영체제 (4)
      • 자료구조 (1)
      • 네트워크 (1)
    • GitHub (1)
    • Python,Django,DRF (13)
    • IOS,Swift (10)
    • 회고 (7)
전체 방문자
오늘
어제
전체
태그
  • #우테코
  • #코틀린
  • #Coroutine
  • #kotlin
  • #ViewModel
  • #Android
  • #코루틴
  • #알고리즘
  • #compose
  • #안드로이드
Copyright © 쭈미로운 생활 All rights reserved.
Designed by JJuum

티스토리툴바