GithubHelp home page GithubHelp logo

coroutineextension's Introduction

使用JitPack快速依赖

How To


allprojects {
  	repositories {
  		...
  		maven { url 'https://jitpack.io' }
  	}
  }

dependencies {
          implementation 'com.github.mistletoe5215:CoroutineExtension:v1.2.3'
  }

更新

v1.3.0

  • 增加View.acquireObservableScope()获取一个跟随窗口移除时取消的协程域

  • 增加Context.acquireLifecycleScope()从只有context的地方获取一个和lifecycle绑定的协程域,协程block执行完即解绑lifecycle

v1.2.3

  • 打包问题修复revert 使用Jitpack ci 的gradle版本

v1.2.2

  • 增加CustomMainDispatcher,解决1.3.2版本主协程调度器crash问题

v1.2.1

  • 增加FJCoroutineDispatcher调度器FJCoroutineDispatcher,可以与Dispatchers.IO做比较

v1.2.0

  • 对网络请求场景使用超时回收策略调度器MCoroutineDispatcher

  • 删除部分无必要父协程Scope创建

v1.1.0

 data class ResponseDataModel1(
          var code:Int = 0,
          var message:String?=null,
          var data:String?=null
    )

 data class ResponseDataModel2(
          var code:Int = 0,
          var message:String?=null,
          var data:String?=null
    )
 @BaseUrl("www.github.com")
 interface ApiService {
         @GET("getListData")
         fun foo1(@Query param:String):Deferred<ResponseDataModel1>
         @GET("getImageData")
         fun foo2(@Query param:String):Deferred<ResponseDataModel2>
  }
 zip(mService.foo1(param), mService.foo2(param))
                .bindLifecycle(activity)
                .onCompletion {
                    val resultList = it.awaitAll()
                    //ensure get all result
                    if(resultList.size == 2){
                        Log.d("Mistletoe",(resultList[0] as ResponseDataModel1)?.data.toString() +"\n"+
                            (resultList[1] as ResponseDataModel2)?.data.toString()
                        )
                    }
                }.catch {
                    Log.e("Mistletoe",it.message)
                }

v1.0.1

        lifecycleOwner promise{
                //请求接口
                mApiService.foo(param)
           } then {
               mResponseDataModel ->
                //返回结果,更新UI
          } catch { e ->
               //捕获异常并在主线程处理异常
          }

UseAge

  • 项目使用retrofit v2.6 时
  data class ResponseDataModel(
        var code:Int = 0,
        var message:String?=null,
        var data:String?=null 
  )
@BaseUrl("www.github.com")
 interface ApiService {
  @GET("getListData")
  suspend fun foo(@Query param:String):ResponseDataModel
  }
     lifecycleOwner.promise{
            //请求接口
            mApiService.foo(param)
       }.then({
           mResponseDataModel ->
            //返回结果,更新UI
      }){ e ->
           //捕获异常并处理 
         }
  • 项目使用retrofit v2.3 时
  @BaseUrl("www.github.com")
    interface ApiService {
     @GET("getListData")
     fun foo(@Query param:String):Deferred<ResponseDataModel>
     }
     lifecycleOwner.promise{
            //请求接口
            mApiService.foo(param)
       }.then({
           mResponseDataModel ->
            //返回结果,更新UI
      }){ e ->
           //捕获异常并处理 
         }
   val handle = setTimeOut(time = 2000L){
         //do delay task
   }
   // cancel task
   handle.cancel()
   val handle = setInterval(Dispatchers.IO, 3000L){
      //do loop task
   }
   // cancel task
   handle.cancel()
 //实现一个3s的倒计时

 val  mFlowCountDownTimer = FlowCountDownTimer.Builder().from(3)
                 .to(0)
                 .interval(1000L)
                 .withUnit(TimeUnit.SECONDS)
                 .create()
             mFlowCountDownTimer?.apply {
                         watchStart {
                             //观察开始动作
                         }
                         watchCountDown {
                             currentCount ->
                            //观察倒计时
                         }
                         watchComplete {
                            //观察倒计时结束
                         }
                     }?.start()
  //希望暂停时, 
  mFlowCountDownTimer?.pause()
  //希望恢复倒计时时,
  mFlowCountDownTimer?.resume()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.