yazinnnn
V2EX  ›  Kotlin

[协程递归问题请教]

  •  
  •   yazinnnn · Nov 18, 2020 · 3195 views
    This topic created in 2001 days ago, the information mentioned may be changed or developed.

    拿实际业务说 以钉钉接口中的跟部门 id [ 1 ] 为开始,递归出公司详细的组织架构

    
    suspend fun getDepart(){
    	fun getSubDepart(pid):List<Department>{
    		val subList:List<departId> = dingApi.getSubDepartList(pid)
    		return subList.map{
    			Department(it,getSubDepart(it))
    		}
    	}
    	return Department(1,getSubDepart(1))
    }
    
    data class Department(val departId,val subList:List<Department>) //sublist 是下属部门列表 
    
    
    

    业务大概如此描述,同步状态下很简单,请问协程要怎么实现呢?

    我用 withcontext ()包裹追钉钉 api,结果 build 时无法通过,报 call to 'resume' before 'invoke' with coroutine

    请问有大佬能帮助一下吗?

    1 replies    2020-11-19 09:45:13 +08:00
    hongch
        1
    hongch  
       Nov 19, 2020
    exception 贴全一点。。。 还少了几个关键词吧
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4212 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 00:07 · PVG 08:07 · LAX 17:07 · JFK 20:07
    ♥ Do have faith in what you're doing.