package com.example.base.common

import androidx.annotation.IntRange
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Flowable
import java.util.concurrent.TimeUnit

/**
 * 描述:rx倒计时
 */

object RxCountDown {
    fun countdown(@IntRange(from = 0, to = Long.MAX_VALUE) time: Long): Flowable<Long> {

        return Flowable.interval(0, 1, TimeUnit.SECONDS)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(AndroidSchedulers.mainThread())
            .map { aLong -> time - aLong }
            .take(time + 1)
    }
}