• 로그인 함 해보끄나?

  • Sarangnamu.net June 17, 2003
    Home Login Profile Study Open Project Q&A Google Code
    rxjava maybe
    https://medium.com/rainist-engineering/migrate-from-rxjava1-to-rxjava2-3aea3ff9051c
    
    // ex1
    Maybe.just("hello").subscribe(
    	::println, // onSuccess
    	{ it.printStackTrace() }, onError
    	{ println("onComplete") }
    
    // output : hello
    
    
    // ex2
    Maybe.fromCallable {
    	val nullableStr: String? = null
    	nullableStr
    }.subscribe(
    	::println, // onSuccess
    	{ it.printStackTrace() }, onError
    	{ println("onComplete") }
    )
    
    // output : onComplete
    
    1번은 데이터가 있으니 hello 가 출력되고 2번은 없어서 onComplete 가 찍힘
    
    
    
    // ex3
    Maybe.fromCallable {
        val nullableStr: String? = null
        nullableStr
    }.flatMapSingle {
        Single.just("Single")
    }.subscribe(
        ::println, // onSuccess
        { it.printStackTrace() } // onError
    )
    // Output > java.util.NoSuchElementException ...
    
    
    // ex4
    Maybe.fromCallable {
        val nullableStr: String? = null
        nullableStr
    }.flatMap {
        Maybe.just("Maybe")
    }.subscribe(
        ::println, // onSuccess
        { it.printStackTrace() }, // onError
        { println("onComplete") } // onComplete
    )
    // Output > onComplete
    
    

    Comment


    입력하3 1542477311



    Locations of visitors to this page