Notice
Recent Posts
Recent Comments
Link
투케이2K
388. (kotlin/코틀린) array 배열에 toObservable 사용해 반응형 프로그래밍 구독 후 데이터 소비 수행 본문
Kotlin
388. (kotlin/코틀린) array 배열에 toObservable 사용해 반응형 프로그래밍 구독 후 데이터 소비 수행
투케이2K 2023. 8. 22. 21:18[개발 환경 설정]
개발 툴 : AndroidStudio
개발 언어 : Kotlin
[소스 코드]
// ---------------------------------------------------------------
// [로직 처리 실시]
// ---------------------------------------------------------------
try {
/**
* --------------------------------------
* [요약 설명]
* --------------------------------------
* 1. toObservable : 반응형 프로그래밍 방식 지원 >> 구독 후 배열 데이터 소비 수행
* --------------------------------------
* 2. 필요 라이브러리 설치 :
*
* implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
* implementation 'io.reactivex.rxjava3:rxkotlin:3.0.1'
* implementation 'io.reactivex.rxjava3:rxjava:3.0.7'
* --------------------------------------
* */
// [array 변수 선언]
var array = arrayOf(1, 2, 3)
array.toObservable()
.observeOn(Schedulers.computation())
.subscribeOn(AndroidSchedulers.mainThread())
.subscribeBy(
onNext = {
S_Log._D_("Observable : onNext", arrayOf( it.toString() ))
},
onError = {
S_Log._E_("Observable : onNext", arrayOf( it.message.toString() ))
},
onComplete = {
S_Log._W_("Observable : onComplete", null)
}
)
}
catch (e : Exception) {
S_Log._printStackTrace_(A_Intro@this, "예외 상황 발생", null, e)
}
[결과 출력]
D///===========//: ================================================
I/: [LOG :: CLASS PLACE :: com.example.kotlinproject.A_Intro$onCreate$4.invoke(A_Intro.kt:173)]
I/: ----------------------------------------------------
I/: [LOG :: NOW TIME :: 2023-08-22 10:18:36 화요일]
I/: ----------------------------------------------------
I/: [LOG :: DESCRIPTION :: Observable : onNext]
I/: ----------------------------------------------------
I/: [LOG :: 1]
D///===========//: ================================================
D///===========//: ================================================
I/: [LOG :: CLASS PLACE :: com.example.kotlinproject.A_Intro$onCreate$4.invoke(A_Intro.kt:173)]
I/: ----------------------------------------------------
I/: [LOG :: NOW TIME :: 2023-08-22 10:18:36 화요일]
I/: ----------------------------------------------------
I/: [LOG :: DESCRIPTION :: Observable : onNext]
I/: ----------------------------------------------------
I/: [LOG :: 2]
D///===========//: ================================================
D///===========//: ================================================
I/: [LOG :: CLASS PLACE :: com.example.kotlinproject.A_Intro$onCreate$4.invoke(A_Intro.kt:173)]
I/: ----------------------------------------------------
I/: [LOG :: NOW TIME :: 2023-08-22 10:18:36 화요일]
I/: ----------------------------------------------------
I/: [LOG :: DESCRIPTION :: Observable : onNext]
I/: ----------------------------------------------------
I/: [LOG :: 3]
D///===========//: ================================================
W///===========//: ================================================
I/: [LOG :: CLASS PLACE :: com.example.kotlinproject.A_Intro$onCreate$3.invoke(A_Intro.kt:179)]
I/: ----------------------------------------------------
I/: [LOG :: NOW TIME :: 2023-08-22 10:18:36 화요일]
I/: ----------------------------------------------------
I/: [LOG :: DESCRIPTION :: Observable : onComplete]
W///===========//: ================================================
반응형
'Kotlin' 카테고리의 다른 글
Comments